38function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
'', $addfieldentry = array(), $delfieldentry =
'')
42 if (empty($objectname)) {
45 if (empty($readdir)) {
49 if (!empty($addfieldentry[
'arrayofkeyval']) && !is_array($addfieldentry[
'arrayofkeyval'])) {
50 dol_print_error(
'',
'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
57 if (is_array($addfieldentry) && count($addfieldentry) > 0) {
58 if (empty($addfieldentry[
'name'])) {
59 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Name")),
null,
'errors');
62 if (empty($addfieldentry[
'label'])) {
63 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
66 if (!preg_match(
'/^(integer|price|sellist|varchar|double|text|html|duration)/', $addfieldentry[
'type'])
67 && !preg_match(
'/^(boolean|smallint|real|date|datetime|timestamp|phone|mail|url|ip|password)$/', $addfieldentry[
'type'])) {
68 setEventMessages($langs->trans(
'BadValueForType', $addfieldentry[
'type']),
null,
'errors');
73 $pathoffiletoeditsrc = $readdir.
'/class/'.strtolower($objectname).
'.class.php';
74 $pathoffiletoedittarget = $destdir.
'/class/'.strtolower($objectname).
'.class.php'.($readdir != $destdir ?
'.new' :
'');
76 $langs->load(
"errors");
77 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc),
null,
'errors');
85 include_once $pathoffiletoeditsrc;
86 if (class_exists($objectname)) {
87 $object =
new $objectname($db);
93 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
96 $contentclass = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
99 if (count($object->fields)) {
100 if (is_array($addfieldentry) && count($addfieldentry)) {
101 $name = $addfieldentry[
'name'];
102 unset($addfieldentry[
'name']);
104 $object->fields[$name] = $addfieldentry;
106 if (!empty($delfieldentry)) {
107 $name = $delfieldentry;
108 unset($object->fields[$name]);
115 $texttoinsert =
'// BEGIN MODULEBUILDER PROPERTIES'.
"\n";
116 $texttoinsert .=
"\t".
'
119 $texttoinsert .=
"\t".
'public $fields=array('.
"\n";
121 if (count($object->fields)) {
122 foreach ($object->fields as $key => $val) {
124 $texttoinsert .=
"\t\t".
'"'.$key.
'" => array(';
125 $texttoinsert .=
'"type"=>"'.dol_escape_php($val[
'type']).
'",';
126 $texttoinsert .=
' "label"=>"'.dol_escape_php($val[
'label']).
'",';
127 if (!empty($val[
'picto'])) {
128 $texttoinsert .=
' "picto"=>"'.dol_escape_php($val[
'picto']).
'",';
130 $texttoinsert .=
' "enabled"=>"'.($val[
'enabled'] !==
'' ?
dol_escape_php($val[
'enabled']) : 1).
'",';
131 $texttoinsert .=
" 'position'=>".($val[
'position'] !==
'' ? (int) $val[
'position'] : 50).
",";
132 $texttoinsert .=
" 'notnull'=>".(empty($val[
'notnull']) ? 0 : (int) $val[
'notnull']).
",";
133 $texttoinsert .=
' "visible"=>"'.($val[
'visible'] !==
'' ?
dol_escape_js($val[
'visible']) : -1).
'",';
134 if (!empty($val[
'noteditable'])) {
135 $texttoinsert .=
' "noteditable"=>"'.dol_escape_php($val[
'noteditable']).
'",';
137 if (!empty($val[
'alwayseditable'])) {
138 $texttoinsert .=
' "alwayseditable"=>"'.dol_escape_php($val[
'alwayseditable']).
'",';
140 if (!empty($val[
'default']) || (isset($val[
'default']) && $val[
'default'] ===
'0')) {
141 $texttoinsert .=
' "default"=>"'.dol_escape_php($val[
'default']).
'",';
143 if (!empty($val[
'index'])) {
144 $texttoinsert .=
' "index"=>"'.(int) $val[
'index'].
'",';
146 if (!empty($val[
'foreignkey'])) {
147 $texttoinsert .=
' "foreignkey"=>"'.(int) $val[
'foreignkey'].
'",';
149 if (!empty($val[
'searchall'])) {
150 $texttoinsert .=
' "searchall"=>"'.(int) $val[
'searchall'].
'",';
152 if (!empty($val[
'isameasure'])) {
153 $texttoinsert .=
' "isameasure"=>"'.(int) $val[
'isameasure'].
'",';
155 if (!empty($val[
'css'])) {
156 $texttoinsert .=
' "css"=>"'.dol_escape_php($val[
'css']).
'",';
158 if (!empty($val[
'cssview'])) {
159 $texttoinsert .=
' "cssview"=>"'.dol_escape_php($val[
'cssview']).
'",';
161 if (!empty($val[
'csslist'])) {
162 $texttoinsert .=
' "csslist"=>"'.dol_escape_php($val[
'csslist']).
'",';
164 if (!empty($val[
'help'])) {
165 $texttoinsert .=
' "help"=>"'.dol_escape_php($val[
'help']).
'",';
167 if (!empty($val[
'showoncombobox'])) {
168 $texttoinsert .=
' "showoncombobox"=>"'.(int) $val[
'showoncombobox'].
'",';
170 if (!empty($val[
'disabled'])) {
171 $texttoinsert .=
' "disabled"=>"'.(int) $val[
'disabled'].
'",';
173 if (!empty($val[
'autofocusoncreate'])) {
174 $texttoinsert .=
' "autofocusoncreate"=>"'.(int) $val[
'autofocusoncreate'].
'",';
176 if (!empty($val[
'arrayofkeyval'])) {
177 $texttoinsert .=
' "arrayofkeyval"=>array(';
179 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
181 $texttoinsert .=
", ";
183 $texttoinsert .=
'"'.dol_escape_php($key2).
'" => "'.
dol_escape_php($val2).
'"';
186 $texttoinsert .=
'),';
188 if (!empty($val[
'validate'])) {
189 $texttoinsert .=
' "validate"=>"'.(int) $val[
'validate'].
'",';
191 if (!empty($val[
'comment'])) {
192 $texttoinsert .=
' "comment"=>"'.dol_escape_php($val[
'comment']).
'"';
195 $texttoinsert .=
"),\n";
200 $texttoinsert .=
"\t".
');'.
"\n";
203 if (count($object->fields)) {
206 foreach ($object->fields as $key => $val) {
209 $texttoinsert .=
"\t".
'public $'.$key.
";";
214 $texttoinsert .=
"\n";
218 $texttoinsert .=
"\t".
'// END MODULEBUILDER PROPERTIES';
222 $contentclass = preg_replace(
'/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
225 dol_mkdir(dirname($pathoffiletoedittarget));
228 $result = file_put_contents(
dol_osencode($pathoffiletoedittarget), $contentclass);
231 dolChmod($pathoffiletoedittarget, $newmask);
236 return $error ? -1 : $object;
238 print $e->getMessage();
256function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir =
'', $object =
null, $moduletype =
'external')
262 if (empty($objectname)) {
265 if (empty($readdir)) {
269 $pathoffiletoclasssrc = $readdir.
'/class/'.strtolower($objectname).
'.class.php';
272 if ($moduletype ==
'internal') {
273 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
274 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
275 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'-'.strtolower($module).
'.sql';
276 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
277 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'-'.strtolower($module).
'.sql';
278 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
279 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'.sql';
284 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
285 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
286 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'-'.strtolower($module).
'.sql';
287 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
288 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'-'.strtolower($module).
'.sql';
289 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
290 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'.sql';
297 $pathoffiletoedittarget = $destdir.$pathoffiletoeditsrc.($readdir != $destdir ?
'.new' :
'');
298 $pathoffiletoeditsrc = $readdir.$pathoffiletoeditsrc;
301 $langs->load(
"errors");
302 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc),
null,
'errors');
308 if (!is_object($object)) {
309 include_once $pathoffiletoclasssrc;
310 if (class_exists($objectname)) {
311 $object =
new $objectname($db);
317 print $e->getMessage();
321 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
323 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
326 $texttoinsert =
'-- BEGIN MODULEBUILDER FIELDS'.
"\n";
327 if (count($object->fields)) {
328 foreach ($object->fields as $key => $val) {
331 $type = $val[
'type'];
332 $type = preg_replace(
'/:.*$/',
'', $type);
334 if ($type ==
'html') {
336 } elseif ($type ==
'price') {
338 } elseif (in_array($type, array(
'link',
'sellist',
'duration'))) {
340 } elseif ($type ==
'mail') {
341 $type =
'varchar(128)';
342 } elseif ($type ==
'phone') {
343 $type =
'varchar(20)';
344 } elseif ($type ==
'ip') {
345 $type =
'varchar(32)';
348 $texttoinsert .=
"\t".$key.
" ".$type;
349 if ($key ==
'rowid') {
350 $texttoinsert .=
' AUTO_INCREMENT PRIMARY KEY';
351 } elseif ($type ==
'timestamp') {
352 $texttoinsert .=
' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP';
354 if ($key ==
'entity') {
355 $texttoinsert .=
' DEFAULT 1';
357 if (!empty($val[
'default'])) {
358 if (preg_match(
'/^null$/i', $val[
'default'])) {
359 $texttoinsert .=
" DEFAULT NULL";
360 } elseif (preg_match(
'/varchar/', $type)) {
361 $texttoinsert .=
" DEFAULT '".$db->escape($val[
'default']).
"'";
363 $texttoinsert .= (($val[
'default'] > 0) ?
' DEFAULT '.$val[
'default'] :
'');
367 $texttoinsert .= ((!empty($val[
'notnull']) && $val[
'notnull'] > 0) ?
' NOT NULL' :
'');
368 if ($i < count($object->fields)) {
369 $texttoinsert .=
", ";
371 $texttoinsert .=
"\n";
374 $texttoinsert .=
"\t".
'-- END MODULEBUILDER FIELDS';
376 $contentsql = preg_replace(
'/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
378 $result = file_put_contents($pathoffiletoedittarget, $contentsql);
380 dolChmod($pathoffiletoedittarget, $newmask);
383 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
387 $pathoffiletoeditsrc = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoeditsrc);
388 $pathoffiletoedittarget = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoedittarget);
389 $pathoffiletoedittarget = preg_replace(
'/\.sql.new$/',
'.key.sql.new', $pathoffiletoedittarget);
391 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
394 $texttoinsert =
'-- BEGIN MODULEBUILDER INDEXES'.
"\n";
395 if (count($object->fields)) {
396 foreach ($object->fields as $key => $val) {
398 if (!empty($val[
'index'])) {
399 $texttoinsert .=
"ALTER TABLE llx_".strtolower($module).
'_'.strtolower($objectname).
" ADD INDEX idx_".strtolower($module).
'_'.strtolower($objectname).
"_".$key.
" (".$key.
");";
400 $texttoinsert .=
"\n";
402 if (!empty($val[
'foreignkey'])) {
403 $tmp = explode(
'.', $val[
'foreignkey']);
404 if (!empty($tmp[0]) && !empty($tmp[1])) {
405 $texttoinsert .=
"ALTER TABLE llx_".strtolower($module).
'_'.strtolower($objectname).
" ADD CONSTRAINT llx_".strtolower($module).
'_'.strtolower($objectname).
"_".$key.
" FOREIGN KEY (".$key.
") REFERENCES llx_".preg_replace(
'/^llx_/',
'', $tmp[0]).
"(".$tmp[1].
");";
406 $texttoinsert .=
"\n";
411 $texttoinsert .=
'-- END MODULEBUILDER INDEXES';
413 $contentsql = preg_replace(
'/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql);
415 dol_mkdir(dirname($pathoffiletoedittarget));
417 $result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
419 dolChmod($pathoffiletoedittarget, $newmask);
422 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
425 return $error ? -1 : 1;
437 $listofobject =
dol_dir_list($destdir.
'/class',
'files', 0,
'\.class\.php$');
438 foreach ($listofobject as $fileobj) {
439 if (preg_match(
'/^api_/', $fileobj[
'name'])) {
442 if (preg_match(
'/^actions_/', $fileobj[
'name'])) {
446 $tmpcontent = file_get_contents($fileobj[
'fullname']);
448 if (preg_match(
'/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
449 $objectnameloop = $reg[1];
450 $objects[$fileobj[
'fullname']] = $objectnameloop;
453 if (count($objects)>0) {
467 if (!file_exists($file)) {
470 $content = file_get_contents($file);
472 if (strpos($content,
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */') !==
false && strpos($content,
'/* END MODULEBUILDER LEFTMENU MYOBJECT */') !==
false) {
475 } elseif ($number === 1) {
476 if (strpos($content,
'/* BEGIN MODULEBUILDER PERMISSIONS */') !==
false && strpos($content,
'/* END MODULEBUILDER PERMISSIONS */') !==
false) {
479 } elseif ($number == 2) {
480 if (strpos($content,
'/* BEGIN MODULEBUILDER DICTIONARIES */') !==
false && strpos($content,
'/* END MODULEBUILDER DICTIONARIES */') !==
false) {
494 $start =
"/* BEGIN MODULEBUILDER PERMISSIONS */";
495 $end =
"/* END MODULEBUILDER PERMISSIONS */";
498 $lines = file($file);
500 foreach ($lines as $i => $line) {
501 if (strpos($line, $start) !==
false) {
502 $start_line = $i + 1;
505 while (($line = $lines[++$i]) !==
false) {
506 if (strpos($line, $end) !==
false) {
515 $allContent = implode(
"", $array);
527 return strcmp($a[0], $b[0]);
546 array_splice($permissions, array_search($permissions[$key], $permissions), 1);
547 } elseif ($action == 1) {
548 array_push($permissions, $right);
549 } elseif ($action == 2 && !empty($right)) {
551 array_splice($permissions, array_search($permissions[$key], $permissions), 1, $right);
552 } elseif ($action == -1 && !empty($objectname)) {
556 foreach ($permissions as $perms) {
557 if ($perms[4] === strtolower($objectname)) {
558 array_splice($permissions, array_search($perms, $permissions), 1);
561 } elseif ($action == -2 && !empty($objectname) && !empty($module)) {
564 $objectOfRights = array();
566 foreach ($permissions as $right) {
567 $objectOfRights[]= $right[4];
569 if (in_array(strtolower($objectname), $objectOfRights)) {
572 $permsToadd = array();
574 'read' =>
'Read '.$objectname.
' object of '.ucfirst($module),
575 'write' =>
'Create/Update '.$objectname.
' object of '.ucfirst($module),
576 'delete' =>
'Delete '.$objectname.
' object of '.ucfirst($module)
579 foreach ($perms as $index => $value) {
580 $permsToadd[$i][0] =
'';
581 $permsToadd[$i][1] = $value;
582 $permsToadd[$i][4] = strtolower($objectname);
583 $permsToadd[$i][5] = $index;
584 array_push($permissions, $permsToadd[$i]);
593 $count_perms = count($permissions);
594 for ($i = 0;$i<$count_perms;$i++) {
595 $permissions[$i][0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1)";
596 $permissions[$i][1] =
"\$this->rights[\$r][1] = '".$permissions[$i][1].
"'";
597 $permissions[$i][4] =
"\$this->rights[\$r][4] = '".$permissions[$i][4].
"'";
598 $permissions[$i][5] =
"\$this->rights[\$r][5] = '".$permissions[$i][5].
"';\n\t\t";
601 $perms_grouped = array();
602 foreach ($permissions as $perms) {
604 if (!isset($perms_grouped[$object])) {
605 $perms_grouped[$object] = [];
607 $perms_grouped[$object][] = $perms;
610 $permissions = $perms_grouped;
615 foreach ($permissions as &$object) {
618 foreach ($object as &$obj) {
619 if (str_contains($obj[5],
'read')) {
620 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 0 + 1)";
621 } elseif (str_contains($obj[5],
'write')) {
622 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 1 + 1)";
623 } elseif (str_contains($obj[5],
'delete')) {
624 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 2 + 1)";
626 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + ".$p.
" + 1)";
630 usort($object,
'compareFirstValue');
635 foreach ($permissions as $perms) {
636 foreach ($perms as $per) {
637 $rights[] = implode(
";\n\t\t", $per);
638 $rights[] =
"\$r++;\n\t\t";
641 $rights_str = implode(
"", $rights);
645 dolReplaceInFile($file, array(
'/* BEGIN MODULEBUILDER PERMISSIONS */' =>
'/* BEGIN MODULEBUILDER PERMISSIONS */'.
"\n\t\t".$rights_str));
660 $string = str_replace(
"'",
'', $string);
663 preg_match_all(
'/\s*([^\s=>]+)\s*=>\s*([^,]+),?/', $string, $matches, PREG_SET_ORDER);
666 foreach ($matches as $match) {
667 $key = trim($match[1]);
668 $value = trim($match[2]);
670 if (strpos($value,
'array(') === 0) {
671 $nestedArray = substr($value, 6);
673 $value = $nestedArray;
674 } elseif (strpos($value,
'"Id")') !==
false) {
675 $value = str_replace(
')',
'', $value);
677 if (is_numeric($value)) {
678 if (strpos($value,
'.') !==
false) {
679 $value = (float) $value;
681 $value = (int) $value;
684 if ($value ===
'true') {
686 } elseif ($value ===
'false') {
691 $propertyArray[$key] = $value;
694 return $propertyArray;
708 $attributesUnique = array(
'type',
'label',
'enabled',
'position',
'notnull',
'visible',
'noteditable',
'index',
'default' ,
'foreignkey',
'arrayofkeyval',
'alwayseditable',
'validate',
'searchall',
'comment',
'isameasure',
'css',
'cssview',
'csslist',
'help',
'showoncombobox',
'picto' );
710 $start =
"public \$fields=array(";
714 $lines = file($file);
716 foreach ($lines as $i => $line) {
717 if (strpos($line, $start) !==
false) {
719 while (($line = $lines[++$i]) !==
false) {
720 if (strpos($line, $end) !==
false) {
729 $table =
"== DATA SPECIFICATIONS\n";
730 $table .=
"=== Table of fields with properties for object *$objectname* : \n";
731 $table .=
"[options='header',grid=rows,frame=topbot,width=100%,caption=Organisation]\n";
735 foreach ($attributesUnique as $attUnique) {
736 $table .=
"|".$attUnique;
739 $valuesModif = array();
740 foreach ($keys as $string) {
741 $string = trim($string,
"'");
742 $string = rtrim($string,
",");
748 foreach ($array as $key => $value) {
749 if (is_array($value)) {
753 $array[$code][$key] = $value;
758 if (!is_array($array)) {
761 $field = array_keys($array);
762 if ($field[0] ===
'') {
765 $values = array_values($array)[0];
768 foreach ($attributesUnique as $attUnique) {
769 if ($attUnique ==
'type' && $field[0] ===
'label') {
770 $values[$attUnique] =
'varchar(255)';
772 if (!array_key_exists($attUnique, $values)) {
773 $valuesModif[$attUnique] =
'';
775 $valuesModif[$attUnique] = $values[$attUnique];
778 $table .=
"|*" . $field[0] .
"*|";
779 $table .= implode(
"|", $valuesModif) .
"\n";
784 $table .=
"__ end table for object $objectname\n";
787 $writeInFile =
dolReplaceInFile($destfile, array(
'== DATA SPECIFICATIONS' => $table));
788 if ($writeInFile<0) {
805 $start =
"== Table of fields and their properties for object *".ucfirst($objectname).
"* : ";
806 $end =
"__ end table for object ".ucfirst($objectname);
808 $str = file_get_contents($file);
810 $search =
'/' . preg_quote($start,
'/') .
'(.*?)' . preg_quote($end,
'/') .
'/s';
811 $new_contents = preg_replace($search,
'', $str);
812 file_put_contents($file, $new_contents);
815 $perms =
"|*".strtolower($objectname).
"*|";
816 $search_pattern_perms =
'/' . preg_quote($perms,
'/') .
'.*?\n/';
817 $new_contents = preg_replace($search_pattern_perms,
'', $new_contents);
818 file_put_contents($file, $new_contents);
835 $lines = file($file);
837 foreach ($lines as $i => $line) {
838 if (strpos($line, $start) !==
false) {
840 while (($line = $lines[++$i]) !==
false) {
841 if (strpos($line, $end) !==
false) {
849 $content = implode(
"", $keys);
863 $start =
'/* BEGIN MODULEBUILDER PERMISSIONS */';
864 $end =
'/* END MODULEBUILDER PERMISSIONS */';
866 if (empty($content)) {
870 $string =
"[options='header',grid=rows,width=60%,caption=Organisation]\n";
873 $header = array($langs->trans(
'Objects'),$langs->trans(
'Permission'));
874 foreach ($header as $h) {
879 $array = explode(
";", $content);
880 $permissions = array_filter($array);
882 $permissions = str_replace(
'$r++', 1, $permissions);
885 foreach ($permissions as $i => $element) {
887 unset($permissions[$i]);
889 if (str_contains($element,
'$this->numero')) {
890 unset($permissions[$i]);
892 if (str_contains($element,
'$this->rights[$r][5]')) {
893 unset($permissions[$i]);
897 foreach ($permissions as $key => $element) {
898 $element = str_replace(
" '",
'', $element);
899 $element = trim($element,
"'");
900 $permsN[] = substr($element, strpos($element,
"=")+1);
907 while ($index < count($permsN)) {
908 $temp_array = [$permsN[$index], $permsN[$index + 1]];
909 $final_array[] = $temp_array;
914 foreach ($final_array as $subarray) {
918 $result[$key][] = $subarray;
920 foreach ($result as $i => $pems) {
921 $string .=
"|*".$i.
"*|";
922 foreach ($pems as $tab) {
923 $string .= $tab[0].
" , ";
928 $string .=
"\n|===\n";
929 $write =
dolReplaceInFile($destfile, array(
'__DATA_PERMISSIONS__'=> $string));
945 if (!file_exists($file)) {
948 $content = file($file);
949 $includeClass =
"dol_include_once('/mymodule/class/myobject.class.php');";
950 $props =
"public \$myobject;";
951 $varcomented =
"@var MyObject \$myobject {@type MyObject}";
952 $constructObj =
"\$this->myobject = new MyObject(\$this->db);";
955 foreach ($content as $lineNumber => &$lineContent) {
956 if (strpos($lineContent, $varcomented) !==
false) {
958 foreach ($objects as $object) {
959 $lineContent .=
"\t * @var ".$object.
" \$".strtolower($object).
" {@type ".$object.
"}". PHP_EOL;
963 if (strpos($lineContent, $props) !==
false) {
965 foreach ($objects as $object) {
966 $lineContent .=
"\tpublic \$".strtolower($object).
";". PHP_EOL;
969 if (strpos($lineContent, $constructObj) !==
false) {
971 foreach ($objects as $object) {
972 $lineContent .=
"\t\t\$this->".strtolower($object).
" = new ".$object.
"(\$this->db);". PHP_EOL;
975 if (strpos($lineContent, $includeClass) !==
false) {
977 foreach ($objects as $object) {
978 $lineContent .=
"dol_include_once('/".strtolower($modulename).
"/class/".strtolower($object).
".class.php');". PHP_EOL;
982 $allContent = implode(
"", $content);
983 file_put_contents($file, $allContent);
986 $allContent =
getFromFile($file,
'/*begin methods CRUD*/',
'/*end methods CRUD*/');
987 foreach ($objects as $object) {
988 $contentReplaced =str_replace([
"myobject",
"MyObject"], [strtolower($object),$object], $allContent);
989 dolReplaceInFile($file, array(
'/*end methods CRUD*/' =>
'/*CRUD FOR '.strtoupper($object).
'*/'.
"\n".$contentReplaced.
"\n\t".
'/*END CRUD FOR '.strtoupper($object).
'*/'.
"\n\t".
'/*end methods CRUD*/'));
991 dolReplaceInFile($file, array($allContent =>
'',
'MyModule' => ucfirst($modulename)));
1004 $begin =
'/*CRUD FOR '.strtoupper($objectname).
'*/';
1005 $end =
'/*END CRUD FOR '.strtoupper($objectname).
'*/';
1006 $includeClass =
"dol_include_once('/".strtolower($modulename).
"/class/".strtolower($objectname).
".class.php');";
1007 $varcomentedDel =
"\t * @var ".$objectname.
" \$".strtolower($objectname).
" {@type ".$objectname.
"}";
1008 $propsDel =
"\tpublic \$".strtolower($objectname).
";";
1009 $constructObjDel =
"\t\t\$this->".strtolower($objectname).
" = new ".$objectname.
"(\$this->db);";
1011 if (!file_exists($file)) {
1014 $content = file($file);
1016 foreach ($content as $lineNumber => &$lineContent) {
1017 if (strpos($lineContent, $includeClass) !==
false) {
1020 if (strpos($lineContent, $varcomentedDel) !==
false) {
1023 if (strpos($lineContent, $propsDel) !==
false) {
1026 if (strpos($lineContent, $constructObjDel) !==
false) {
1030 $allContent = implode(
"", $content);
1031 file_put_contents($file, $allContent);
1054 if (!file_exists($file)) {
1057 if ($action == 0 && !empty($key)) {
1059 array_splice($menus, array_search($menus[$key], $menus), 1);
1060 } elseif ($action == 1) {
1062 array_push($menus, $menuWantTo);
1063 } elseif ($action == 2 && !empty($key) && !empty($menuWantTo)) {
1067 foreach ($menus as $index => $menu) {
1068 if ($index !== $key) {
1069 if ($menu[
'type'] === $menuWantTo[
'type']) {
1070 if (strcasecmp(str_replace(
' ',
'', $menu[
'titre']), str_replace(
' ',
'', $menuWantTo[
'titre'])) === 0) {
1073 if (strcasecmp(str_replace(
' ',
'', $menu[
'url']), str_replace(
' ',
'', $menuWantTo[
'url'])) === 0) {
1079 if (!$counter && $urlCounter < 2) {
1080 $menus[$key] = $menuWantTo;
1084 } elseif ($action == -1 && !empty($menuWantTo)) {
1086 foreach ($menus as $index => $menu) {
1087 if ((strpos(strtolower($menu[
'fk_menu']), strtolower($menuWantTo)) !==
false) || (strpos(strtolower($menu[
'leftmenu']), strtolower($menuWantTo)) !==
false)) {
1088 array_splice($menus, array_search($menu, $menus), 1);
1096 $beginMenu =
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */';
1097 $endMenu =
'/* END MODULEBUILDER LEFTMENU MYOBJECT */';
1098 $allMenus =
getFromFile($file, $beginMenu, $endMenu);
1103 foreach ($menus as $index => $menu) {
1104 $menu[
'position'] =
"1000 + \$r";
1105 if ($menu[
'type'] ===
'left') {
1106 $start =
"\t\t".
'/* LEFTMENU '.strtoupper($menu[
'titre']).
' */';
1107 $end =
"\t\t".
'/* END LEFTMENU '.strtoupper($menu[
'titre']).
' */';
1109 $val_actuel = $menu;
1110 $next_val = empty($menus[$index + 1]) ? null : $menus[$index + 1];
1113 $str_menu .= $start.
"\n";
1114 $str_menu.=
"\t\t\$this->menu[\$r++]=array(\n";
1115 $str_menu.=
"\t\t\t 'fk_menu' => '".dol_escape_php($menu[
'fk_menu'], 1).
"',\n";
1116 $str_menu.=
"\t\t\t 'type' => '".dol_escape_php($menu[
'type'], 1).
"',\n";
1117 $str_menu.=
"\t\t\t 'titre' => '".dol_escape_php($menu[
'titre'], 1).
"',\n";
1118 $str_menu.=
"\t\t\t 'mainmenu' => '".dol_escape_php($menu[
'mainmenu'], 1).
"',\n";
1119 $str_menu.=
"\t\t\t 'leftmenu' => '".dol_escape_php($menu[
'leftmenu'], 1).
"',\n";
1120 $str_menu.=
"\t\t\t 'url' => '".dol_escape_php($menu[
'url'], 1).
"',\n";
1121 $str_menu.=
"\t\t\t 'langs' => '".dol_escape_php($menu[
'langs'], 1).
"',\n";
1122 $str_menu.=
"\t\t\t 'position' => ".((int) $menu[
'position']).
",\n";
1123 $str_menu.=
"\t\t\t 'enabled' => '".dol_escape_php($menu[
'enabled'], 1).
"',\n";
1124 $str_menu.=
"\t\t\t 'perms' => '".dol_escape_php($menu[
'perms'], 1).
"',\n";
1125 $str_menu.=
"\t\t\t 'target' => '".dol_escape_php($menu[
'target'], 1).
"',\n";
1126 $str_menu.=
"\t\t\t 'user' => ".((int) $menu[
'user']).
",\n";
1127 $str_menu.=
"\t\t);\n";
1129 if (is_null($next_val) || $val_actuel[
'leftmenu'] !== $next_val[
'leftmenu']) {
1130 $str_menu .= $end.
"\n";
1135 dolReplaceInFile($file, array($beginMenu => $beginMenu.
"\n".$str_menu.
"\n"));
1152 $dicData =
"\t\t\$this->dictionaries=array(\n";
1153 $module = strtolower($module);
1154 foreach ($dicts as $key => $value) {
1155 if (empty($value)) {
1157 $dicData =
"\t\t\$this->dictionaries=array();";
1161 $dicData .=
"\t\t\t'$key'=>";
1163 if ($key ===
'tabcond') {
1164 $conditions = array_map(
function ($val) use ($module) {
1165 return ($val ===
true || $val ===
false) ?
"isModEnabled('$module')" : $val;
1167 $dicData .=
"array(" . implode(
",", $conditions) .
")";
1168 } elseif ($key ===
'tabhelp') {
1169 $helpItems = array();
1170 foreach ($value as $helpValue) {
1171 $helpItems[] =
"array('code'=>\$langs->trans('".$helpValue[
'code'].
"'), 'field2' => 'field2tooltip')";
1173 $dicData .=
"array(" . implode(
",", $helpItems) .
")";
1175 if (is_array($value)) {
1176 $dicData .=
"array(" . implode(
",", array_map(
function ($val) {
1180 $dicData .=
"'$value'";
1185 $dicData .= (!$isEmpty ?
"\t\t);" :
'');
1187 $stringDic =
getFromFile($file,
'/* BEGIN MODULEBUILDER DICTIONARIES */',
'/* END MODULEBUILDER DICTIONARIES */');
1188 $writeInfile =
dolReplaceInFile($file, array($stringDic => $dicData.
"\n"));
1190 return $writeInfile;
1209 if (empty($namedic)) {
1213 if (!file_exists($file)) {
1216 $modulename = strtolower($modulename);
1218 if (empty($dictionnaires)) {
1219 $dictionnaires = array(
'langs' =>
'',
'tabname' => array(),
'tablib' => array(),
'tabsql' => array(),
'tabsqlsort' => array(),
'tabfield' => array(),
'tabfieldvalue' => array(),
'tabfieldinsert' => array(),
'tabrowid' => array(),
'tabcond' => array(),
'tabhelp' => array());
1223 'rowid' => array(
'type' =>
'integer(11)'),
1224 'code' => array(
'type' =>
'varchar(255) NOT NULL'),
1225 'label' => array(
'type' =>
'varchar(255) NOT NULL'),
1226 'position' => array(
'type' =>
'integer(11) NULL'),
1227 'use_default' => array(
'type' =>
'varchar(255) DEFAULT 1'),
1228 'active' => array(
'type' =>
'integer')
1232 $primaryKey =
'rowid';
1233 foreach ($columns as $key => $value) {
1234 if ($key ===
'rowid') {
1235 $primaryKey =
'rowid';
1238 if (!array_key_exists(
'rowid', $columns)) {
1239 $primaryKey = array_key_first($columns);
1244 $query =
"SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($namedic) .
"'";
1245 $checkTable = $db->query($query);
1246 if ($checkTable && $db->num_rows($checkTable) > 0) {
1247 setEventMessages($langs->trans(
"ErrorTableExist", $namedic),
null,
'errors');
1250 $_results = $db->DDLCreateTable(MAIN_DB_PREFIX.strtolower($namedic), $columns, $primaryKey,
"InnoDB");
1251 if ($_results < 0) {
1253 $langs->load(
"errors");
1254 setEventMessages($langs->trans(
"ErrorTableNotFound", $namedic),
null,
'errors');
1259 $dictionnaires[
'langs'] = $modulename.
'@'.$modulename;
1260 $dictionnaires[
'tabname'][] = strtolower($namedic);
1261 $dictionnaires[
'tablib'][] = ucfirst(substr($namedic, 2));
1262 $dictionnaires[
'tabsql'][] =
'SELECT t.rowid as rowid, t.code, t.label, t.active FROM '.MAIN_DB_PREFIX.strtolower($namedic).
' as t';
1263 $dictionnaires[
'tabsqlsort'][] = (array_key_exists(
'label', $columns) ?
'label ASC' :
'');
1264 $dictionnaires[
'tabfield'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1265 $dictionnaires[
'tabfieldvalue'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1266 $dictionnaires[
'tabfieldinsert'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1267 $dictionnaires[
'tabrowid'][] = $primaryKey;
1268 $dictionnaires[
'tabcond'][] = isModEnabled(
'$modulename');
1269 $dictionnaires[
'tabhelp'][] = (array_key_exists(
'code', $columns) ? array(
'code'=>$langs->trans(
'CodeTooltipHelp'),
'field2' =>
'field2tooltip') :
'');
1273 if ($writeInfile > 0) {
1274 setEventMessages($langs->trans(
"DictionariesCreated", ucfirst(substr($namedic, 2))),
null);
1291 $string =
getFromFile($file_api,
'/*begin methods CRUD*/',
'/*end methods CRUD*/');
1292 $extractUrls = explode(
"\n", $string);
1296 foreach ($extractUrls as $key => $line) {
1297 $lineWithoutTabsSpaces = preg_replace(
'/^[\t\s]+/',
'', $line);
1298 if (strpos($lineWithoutTabsSpaces,
'* @url') === 0) {
1299 $urlValue = trim(substr($lineWithoutTabsSpaces, strlen(
'* @url')));
1300 $urlValues[] = $urlValue;
1305 $str = $_SERVER[
'HTTP_HOST'].
'/api/index.php/';
1307 foreach ($urlValues as $url) {
1308 if (preg_match(
'/(?:GET|POST|PUT|DELETE) (\w+)s/', $url, $matches)) {
1309 $objectName = $matches[1];
1310 $url = $str.trim(strstr($url,
' '));
1311 $groupedUrls[$objectName][] = $url;
1314 if (empty($groupedUrls)) {
1320 $asciiDocTable =
"[options=\"header\"]\n|===\n|Objet | URLs\n";
1321 foreach ($groupedUrls as $objectName => $urls) {
1322 $urlsList = implode(
" +\n*", $urls);
1323 $asciiDocTable .=
"|$objectName | \n*$urlsList +\n";
1325 $asciiDocTable .=
"|===\n";
1326 $file_write =
dolReplaceInFile($file_doc, array(
'__API_DOC__' =>
'__API_DOC__'.
"\n".$asciiDocTable));
1327 if ($file_write < 0) {
1344 if (!is_dir($path)) {
1348 $allFilesAndDirs = scandir($path);
1351 foreach ($allFilesAndDirs as $item) {
1352 if ($item !=
'.' && $item !=
'..') {
1353 if ($type == 1 && is_file($path . DIRECTORY_SEPARATOR . $item) && strpos($item,
'.back') ===
false) {
1355 } elseif ($type == 2 && is_dir($path . DIRECTORY_SEPARATOR . $item)) {
dol_is_file($pathoffile)
Return if path is a file.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_escape_php($stringtoescape, $stringforquotes=2)
Returns text escaped for inclusion into a php string, build with double quotes " or '.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
updateDictionaryInFile($module, $file, $dicts)
Updates a dictionary in a module descriptor file.
deletePropsAndPermsFromDoc($file, $objectname)
Delete property and permissions from documentation ascii file if we delete an object.
createNewDictionnary($modulename, $file, $namedic, $dictionnaires=null)
Creates a new dictionary table.
countItemsInDirectory($path, $type=1)
count directories or files in modulebuilder folder
writePermsInAsciiDoc($file, $destfile)
Write all permissions of each object in AsciiDoc format.
reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
parsePropertyString($string)
Converts a formatted properties string into an associative array.
rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null, $moduletype='external')
Save data into a memory area shared by all users, all sessions on server.
writeApiUrlsInDoc($file_api, $file_doc)
Generate Urls and add them to documentaion module.
addObjectsToApiFile($file, $objects, $modulename)
Add Object in ModuleApi File.
dolGetListOfObjectClasses($destdir)
Get list of existing objects from directory.
deletePerms($file)
Delete all permissions.
writePropsInAsciiDoc($file, $objectname, $destfile)
Write all properties of the object in AsciiDoc format.
compareFirstValue($a, $b)
Compare two value.
removeObjectFromApiFile($file, $objectname, $modulename)
Remove Object variables and methods from API_Module File.
rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array(), $delfieldentry='')
Regenerate files .class.php.
getFromFile($file, $start, $end)
Search a string and return all lines needed from file.
reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action)
Rewriting all permissions after any actions.
checkExistComment($file, $number)
function for check if comment begin an end exist in modMyModule class