Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
usercard_importvcard.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Import VCARD files
9  *
10  * @author Anakeen 2000
11  * @version $Id: usercard_importvcard.php,v 1.16 2005/11/23 14:03:50 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage USERCARD
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Dir.php");
20 include_once ("FDL/Class.UsercardVcard.php");
21 include_once ("GENERIC/generic_util.php");
22 
24 {
25  global $_FILES;
26  // Get all the params
27  $id = GetHttpVars("id");
28  $dbaccess = $action->GetParam("FREEDOM_DB");
29  $policy = GetHttpVars("policy", "add");
30  $category = GetHttpVars("category");
31  $privacity = GetHttpVars("privacity", "R");
32 
33  $action->lay->Set("CR", "");
34  $vcard_import = new UsercardVcard();
35 
36  if (isset($_FILES["vcardfile"])) {
37  // importation
38  $vcardfile = $_FILES["vcardfile"]["tmp_name"];
39  } else {
40  $vcardfile = GetHttpVars("file");
41  }
42  if (!$vcard_import->Open($vcardfile)) $action->exitError(_("no vcard file specified"));
43 
44  $tvalue = array();
45 
46  $tabadd = array(); // memo each added person
47  $tabdel = array(); // memo each deleted person
48  while ($vcard_import->Read($tvalue)) {
49 
50  if (count($tvalue) > 0) {
51  // Add new contact card
52  $doc = createDoc($dbaccess, "USER");
53 
54  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , "USER"));
55 
56  $doc->Add();
57  // set privacity
58  $doc->setvalue("US_PRIVCARD", $privacity);
59 
60  while (list($k, $v) = each($tvalue)) {
61  $doc->setvalue($k, $v);
62  }
63  $doc->refresh();
64  $doc->Modify();
65  // add in each selected category
66  if (is_array($category)) {
67  reset($category);
68 
69  while (list($k, $v) = each($category)) {
70 
71  $catg = new_Doc($dbaccess, $v);
72  $catg->AddFile($doc->id);
73  }
74  }
75  // duplicate policy
76  switch ($policy) {
77  case "add":
78  $doc->PostModify();
79  $tabadd[] = array(
80  "id" => $doc->id,
81  "title" => $doc->title
82  );
83  break;
84 
85  case "update":
86 
87  $doc->PostModify();
88  $tabadd[] = array(
89  "id" => $doc->id,
90  "title" => $doc->title
91  );
92  $ldoc = $doc->GetDocWithSameTitle();
93  while (list($k, $v) = each($ldoc)) {
94  $err = $v->delete(); // delete all double (if has permission)
95  $tabdel[] = array(
96  "id" => $v->id,
97  "title" => $v->title
98  );
99  }
100  break;
101 
102  case "keep":
103  $ldoc = $doc->GetDocWithSameTitle();
104  if (count($ldoc) == 0) {
105  $doc->PostModify();
106  $tabadd[] = array(
107  "id" => $doc->id,
108  "title" => $doc->title
109  );
110  } else {
111  // delete the new added doc
112  $doc->delete();
113  }
114  break;
115  }
116  }
117  }
118  $vcard_import->Close();
119 
120  $action->lay->SetBlockData("ADDED", $tabadd);
121  $action->lay->SetBlockData("DELETED", $tabdel);
122 }
123 ?>
← centre documentaire © anakeen - published under CC License - Dynacase