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);
24 function __construct($docman, $group_id) {
25 $this->docman = $docman;
26 $this->group_id = $group_id;
27 $group =& group_get_object($group_id);
28 if (!$group || !is_object($group)) {
29 print "error retrieving group from id";
30 } elseif ($group->isError()) {
33 $this->group = $group;
36 function checkDocGrpExistence($doc_group_name,$parent_doc_group_id){
37 if ($id = $this->doc_group_ids[$parent_doc_group_id][$doc_group_name]){
38 //this name already exists in the directory of id $parent_doc_group_id
44 function addFile($params, $parent_dir_id, $status="active"){
46 echo "Adding file:".$params["given_name"]." at directory:".$parent_dir_id;
48 $path = '/tmp/'.$params['url'];
50 $doc = new Document($this->group);
52 $fn = $params["file_name"];
53 $ftitle = $params["given_name"];
54 $fdata = file_get_contents($path);
55 $fdocgrp = $parent_dir_id;
56 $flanguage = $this->language_ids[$params["language"]];
57 $fdesc = $params["description"];
58 $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // Retourne le type mime
60 echo "error opening fileinfo";
63 $ftype = $finfo->file($path);
65 $doc->create($fn,$ftype,$fdata,$fdocgrp,$ftitle,$flanguage,$fdesc);
68 $fstate_id = $this->docman_states[$status];
69 $doc->update($fn, $ftype, $fdata, $fdocgrp, $ftitle, $flanguage, $fdesc,$fstate_id);
75 function addDirectory($dirName, $parent_dir_id){
77 //root of the current type
78 echo "ROOT:".$dirName;
80 //is dir already existing?
81 if(!$dirid = $this->checkDocGrpExistence($dirName, $parent_dir_id)){
82 //dir does not exist : create
83 $doc_group = new DocumentGroup($this->group);
84 $doc_group->create($dirName);
85 $dirid = $doc_group->getID();
86 $this->doc_group_ids[$parent_dir_id][$dirName] = $dirid;
88 //dir exists : return its id
92 echo $parent_dir.":".$dirName;
94 //is dir already existing?
95 if(!$dirid = $this->checkDocGrpExistence($dirName, $parent_dir_id)){
96 //dir does not exist : create
97 $doc_group = new DocumentGroup($this->group);
98 $doc_group->create($dirName, $parent_dir_id);
99 $dirid = $doc_group->getID();
100 $this->doc_group_ids[$parent_dir_id][$dirName] = $dirid;
102 //dir exists : return its id
109 $gr = new DocumentGroupFactory($this->group);
110 $dgroups = $gr->getDocumentGroups();
111 foreach($dgroups as $dg){
112 if($dg->getParentID()==0 && $dg->getName()=='Uncategorized Submissions'){
119 function fill_type($content, $status = "", $parent_dir_id = ""){
120 // while (len($content) != 0){
121 // $c = array_pop($content);
122 foreach($content as $k => $v){
123 if(array_key_exists("class", $v) && $v["class"] == "FILE"){
125 $this->addFile($v, $parent_dir_id, $status);
128 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
129 $dirid = $this->addDirectory($k, $parent_dir_id);
131 //get Uncategorized Submissions doc_group
132 $dirid = $this->getUncat();
134 //error : no Uncategorized subs for this project for unknown reason
136 $dirid = $this->addDirectory($k, $parent_dir_id);
140 $this->fill_type($v,$status,$dirid);
145 function docman_fill(){
146 $r1 = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
147 array ($this->group_id)) ;
149 $r2 = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
150 array ($this->group_id)) ;
153 foreach($this->docman as $status => $content){
154 $this->fill_type($content, $status);