3 require_once '../env.inc.php';
4 require_once $gfwww.'include/pre.php';
5 require_once $gfcommon.'docman/DocumentGroup.class.php';
6 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
7 require_once $gfcommon.'docman/Document.class.php';
11 public $doc_group_ids = array();
17 public $language_ids = array("Bulgarian" => 20, "Catalan" => 14, "Dutch" => 12, "English" => 1, "Esperanto" =>13, "French" =>7, "Greek" => 19, "German" =>6, "Hebrew" =>3,
18 "Indonesian" =>21, "Italian" => 8, "Japanese" =>2, "Korean" => 22, "Latin" => 25, "Norwegian" =>9, "Polish" =>15, "Portuguese" =>18, "Pt. Brazilian" =>16, "Russian" => 17,
19 "Smpl.Chinese" =>23, "Spanish" =>4, "Swedish" =>10, "Thai" =>5, "Trad.Chinese" =>11);
21 public $docman_states = array("active"=>1, "deleted"=>2, "pending"=>3, "hidden"=>4, "private"=>5);
23 function __construct($docman, $group_id) {
24 $this->docman = $docman;
25 $this->group_id = $group_id;
26 $group = group_get_object($group_id);
27 if (!$group || !is_object($group)) {
28 print "error retrieving group from id";
29 } elseif ($group->isError()) {
32 $this->group = $group;
35 function checkDocGrpExistence($doc_group_name,$parent_doc_group_id){
36 if ($id = $this->doc_group_ids[$parent_doc_group_id][$doc_group_name]){
37 //this name already exists in the directory of id $parent_doc_group_id
43 function addFile($params, $parent_dir_id, $status="active"){
45 echo "Adding file:".$params["given_name"]." at directory:".$parent_dir_id;
47 $path = '/tmp/'.$params['url'];
49 $doc = new Document($this->group);
51 $fn = $params["file_name"];
52 $ftitle = $params["given_name"];
53 $fdata = file_get_contents($path);
54 $fdocgrp = $parent_dir_id;
55 $flanguage = $this->language_ids[$params["language"]];
56 $fdesc = $params["description"];
57 $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // Retourne le type mime
59 echo "error opening fileinfo";
62 $ftype = $finfo->file($path);
64 $doc->create($fn,$ftype,$fdata,$fdocgrp,$ftitle,$flanguage,$fdesc);
67 $fstate_id = $this->docman_states[$status];
68 $doc->update($fn, $ftype, $fdata, $fdocgrp, $ftitle, $flanguage, $fdesc,$fstate_id);
72 function addDirectory($dirName, $parent_dir_id){
74 //root of the current type
75 echo "ROOT:".$dirName;
77 //is dir already existing?
78 if(!$dirid = $this->checkDocGrpExistence($dirName, $parent_dir_id)){
79 //dir does not exist : create
80 $doc_group = new DocumentGroup($this->group);
81 $doc_group->create($dirName);
82 $dirid = $doc_group->getID();
83 $this->doc_group_ids[$parent_dir_id][$dirName] = $dirid;
85 //dir exists : return its id
89 echo $parent_dir.":".$dirName;
91 //is dir already existing?
92 if(!$dirid = $this->checkDocGrpExistence($dirName, $parent_dir_id)){
93 //dir does not exist : create
94 $doc_group = new DocumentGroup($this->group);
95 $doc_group->create($dirName, $parent_dir_id);
96 $dirid = $doc_group->getID();
97 $this->doc_group_ids[$parent_dir_id][$dirName] = $dirid;
99 //dir exists : return its id
106 $gr = new DocumentGroupFactory($this->group);
107 $dgroups = $gr->getDocumentGroups();
108 foreach($dgroups as $dg){
109 if($dg->getParentID()==0 && $dg->getName()=='Uncategorized Submissions'){
116 function fill_type($content, $status = "", $parent_dir_id = ""){
117 // while (len($content) != 0){
118 // $c = array_pop($content);
119 foreach($content as $k => $v){
120 if(array_key_exists("class", $v) && $v["class"] == "FILE"){
122 $this->addFile($v, $parent_dir_id, $status);
125 if($k!='Uncategorized Submissions'){ //Uncategorized subs is a basic category which should not be duplicated, we need to get its id to add docs to it though
126 $dirid = $this->addDirectory($k, $parent_dir_id);
128 //get Uncategorized Submissions doc_group
129 $dirid = $this->getUncat();
131 //error : no Uncategorized subs for this project for unknown reason
133 $dirid = $this->addDirectory($k, $parent_dir_id);
137 $this->fill_type($v,$status,$dirid);
142 function docman_fill(){
143 $r1 = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
144 array ($this->group_id)) ;
146 $r2 = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
147 array ($this->group_id)) ;
149 foreach($this->docman as $status => $content){
150 $this->fill_type($content, $status);