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('type'=>'".$val[
'type'].
"',";
125 $texttoinsert .=
" 'label'=>'".$val[
'label'].
"',";
126 if (!empty($val[
'picto'])) {
127 $texttoinsert .=
" 'picto'=>'".$val[
'picto'].
"',";
129 $texttoinsert .=
" 'enabled'=>'".($val[
'enabled'] !==
'' ? $val[
'enabled'] : 1).
"',";
130 $texttoinsert .=
" 'position'=>".($val[
'position'] !==
'' ? $val[
'position'] : 50).
",";
131 $texttoinsert .=
" 'notnull'=>".(empty($val[
'notnull']) ? 0 : $val[
'notnull']).
",";
132 $texttoinsert .=
" 'visible'=>".($val[
'visible'] !==
'' ? $val[
'visible'] : -1).
",";
133 if (!empty($val[
'noteditable'])) {
134 $texttoinsert .=
" 'noteditable'=>'".$val[
'noteditable'].
"',";
136 if (!empty($val[
'alwayseditable'])) {
137 $texttoinsert .=
" 'alwayseditable'=>'".$val[
'alwayseditable'].
"',";
139 if (!empty($val[
'default']) || (isset($val[
'default']) && $val[
'default'] ===
'0')) {
140 $texttoinsert .=
" 'default'=>'".$val[
'default'].
"',";
142 if (!empty($val[
'index'])) {
143 $texttoinsert .=
" 'index'=>".$val[
'index'].
",";
145 if (!empty($val[
'foreignkey'])) {
146 $texttoinsert .=
" 'foreignkey'=>'".$val[
'foreignkey'].
"',";
148 if (!empty($val[
'searchall'])) {
149 $texttoinsert .=
" 'searchall'=>".$val[
'searchall'].
",";
151 if (!empty($val[
'isameasure'])) {
152 $texttoinsert .=
" 'isameasure'=>'".$val[
'isameasure'].
"',";
154 if (!empty($val[
'css'])) {
155 $texttoinsert .=
" 'css'=>'".$val[
'css'].
"',";
157 if (!empty($val[
'cssview'])) {
158 $texttoinsert .=
" 'cssview'=>'".$val[
'cssview'].
"',";
160 if (!empty($val[
'csslist'])) {
161 $texttoinsert .=
" 'csslist'=>'".$val[
'csslist'].
"',";
163 if (!empty($val[
'help'])) {
164 $texttoinsert .=
" 'help'=>\"".preg_replace(
'/"/',
'', $val[
'help']).
"\",";
166 if (!empty($val[
'showoncombobox'])) {
167 $texttoinsert .=
" 'showoncombobox'=>'".$val[
'showoncombobox'].
"',";
169 if (!empty($val[
'disabled'])) {
170 $texttoinsert .=
" 'disabled'=>'".$val[
'disabled'].
"',";
172 if (!empty($val[
'autofocusoncreate'])) {
173 $texttoinsert .=
" 'autofocusoncreate'=>'".$val[
'autofocusoncreate'].
"',";
175 if (!empty($val[
'arrayofkeyval'])) {
176 $texttoinsert .=
" 'arrayofkeyval'=>array(";
178 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
180 $texttoinsert .=
", ";
182 $texttoinsert .=
"'".$key2.
"'=>'".$val2.
"'";
185 $texttoinsert .=
"),";
187 if (!empty($val[
'validate'])) {
188 $texttoinsert .=
" 'validate'=>'".$val[
'validate'].
"',";
190 if (!empty($val[
'comment'])) {
191 $texttoinsert .=
" 'comment'=>\"".preg_replace(
'/"/',
'', $val[
'comment']).
"\"";
194 $texttoinsert .=
"),\n";
199 $texttoinsert .=
"\t".
');'.
"\n";
202 if (count($object->fields)) {
205 foreach ($object->fields as $key => $val) {
208 $texttoinsert .=
"\t".
'public $'.$key.
";";
213 $texttoinsert .=
"\n";
217 $texttoinsert .=
"\t".
'// END MODULEBUILDER PROPERTIES';
221 $contentclass = preg_replace(
'/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
224 dol_mkdir(dirname($pathoffiletoedittarget));
227 $result = file_put_contents(
dol_osencode($pathoffiletoedittarget), $contentclass);
230 dolChmod($pathoffiletoedittarget, $newmask);
235 return $error ? -1 : $object;
237 print $e->getMessage();
255function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir =
'', $object =
null, $moduletype =
'external')
261 if (empty($objectname)) {
264 if (empty($readdir)) {
268 $pathoffiletoclasssrc = $readdir.
'/class/'.strtolower($objectname).
'.class.php';
271 if ($moduletype ==
'internal') {
272 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
273 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
274 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'-'.strtolower($module).
'.sql';
275 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
276 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'-'.strtolower($module).
'.sql';
277 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
278 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.strtolower($module).
'.sql';
283 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
284 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
285 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'-'.strtolower($module).
'.sql';
286 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
287 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'-'.strtolower($module).
'.sql';
288 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
289 $pathoffiletoeditsrc =
'/sql/llx_'.strtolower($module).
'.sql';
296 $pathoffiletoedittarget = $destdir.$pathoffiletoeditsrc.($readdir != $destdir ?
'.new' :
'');
297 $pathoffiletoeditsrc = $readdir.$pathoffiletoeditsrc;
300 $langs->load(
"errors");
301 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc),
null,
'errors');
307 if (!is_object($object)) {
308 include_once $pathoffiletoclasssrc;
309 if (class_exists($objectname)) {
310 $object =
new $objectname($db);
316 print $e->getMessage();
320 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
322 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
325 $texttoinsert =
'-- BEGIN MODULEBUILDER FIELDS'.
"\n";
326 if (count($object->fields)) {
327 foreach ($object->fields as $key => $val) {
330 $type = $val[
'type'];
331 $type = preg_replace(
'/:.*$/',
'', $type);
333 if ($type ==
'html') {
335 } elseif ($type ==
'price') {
337 } elseif (in_array($type, array(
'link',
'sellist',
'duration'))) {
340 $texttoinsert .=
"\t".$key.
" ".$type;
341 if ($key ==
'rowid') {
342 $texttoinsert .=
' AUTO_INCREMENT PRIMARY KEY';
343 } elseif ($type ==
'timestamp') {
344 $texttoinsert .=
' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP';
346 if ($key ==
'entity') {
347 $texttoinsert .=
' DEFAULT 1';
349 if (!empty($val[
'default'])) {
350 if (preg_match(
'/^null$/i', $val[
'default'])) {
351 $texttoinsert .=
" DEFAULT NULL";
352 } elseif (preg_match(
'/varchar/', $type)) {
353 $texttoinsert .=
" DEFAULT '".$db->escape($val[
'default']).
"'";
355 $texttoinsert .= (($val[
'default'] > 0) ?
' DEFAULT '.$val[
'default'] :
'');
359 $texttoinsert .= ((!empty($val[
'notnull']) && $val[
'notnull'] > 0) ?
' NOT NULL' :
'');
360 if ($i < count($object->fields)) {
361 $texttoinsert .=
", ";
363 $texttoinsert .=
"\n";
366 $texttoinsert .=
"\t".
'-- END MODULEBUILDER FIELDS';
368 $contentsql = preg_replace(
'/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
370 $result = file_put_contents($pathoffiletoedittarget, $contentsql);
372 dolChmod($pathoffiletoedittarget, $newmask);
375 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
379 $pathoffiletoeditsrc = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoeditsrc);
380 $pathoffiletoedittarget = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoedittarget);
381 $pathoffiletoedittarget = preg_replace(
'/\.sql.new$/',
'.key.sql.new', $pathoffiletoedittarget);
383 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
386 $texttoinsert =
'-- BEGIN MODULEBUILDER INDEXES'.
"\n";
387 if (count($object->fields)) {
388 foreach ($object->fields as $key => $val) {
390 if (!empty($val[
'index'])) {
391 $texttoinsert .=
"ALTER TABLE llx_".strtolower($module).
'_'.strtolower($objectname).
" ADD INDEX idx_".strtolower($module).
'_'.strtolower($objectname).
"_".$key.
" (".$key.
");";
392 $texttoinsert .=
"\n";
394 if (!empty($val[
'foreignkey'])) {
395 $tmp = explode(
'.', $val[
'foreignkey']);
396 if (!empty($tmp[0]) && !empty($tmp[1])) {
397 $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].
");";
398 $texttoinsert .=
"\n";
403 $texttoinsert .=
'-- END MODULEBUILDER INDEXES';
405 $contentsql = preg_replace(
'/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql);
407 dol_mkdir(dirname($pathoffiletoedittarget));
409 $result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
411 dolChmod($pathoffiletoedittarget, $newmask);
414 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
417 return $error ? -1 : 1;
429 $listofobject =
dol_dir_list($destdir.
'/class',
'files', 0,
'\.class\.php$');
430 foreach ($listofobject as $fileobj) {
431 if (preg_match(
'/^api_/', $fileobj[
'name'])) {
434 if (preg_match(
'/^actions_/', $fileobj[
'name'])) {
438 $tmpcontent = file_get_contents($fileobj[
'fullname']);
440 if (preg_match(
'/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
441 $objectnameloop = $reg[1];
442 $objects[$fileobj[
'fullname']] = $objectnameloop;
445 if (count($objects)>0) {
460 $start =
"/* BEGIN MODULEBUILDER PERMISSIONS */";
461 $end =
"/* END MODULEBUILDER PERMISSIONS */";
464 $lines = file($file);
466 foreach ($lines as $i => $line) {
467 if (strpos($line, $start) !==
false) {
468 $start_line = $i + 1;
471 while (($line = $lines[++$i]) !==
false) {
472 if (strpos($line, $end) !==
false) {
481 $allContent = implode(
"", $array);
493 return strcmp($a[0], $b[0]);
512 array_splice($permissions, array_search($permissions[$key], $permissions), 1);
513 } elseif ($action == 1) {
514 array_push($permissions, $right);
515 } elseif ($action == 2 && !empty($right)) {
517 array_splice($permissions, array_search($permissions[$key], $permissions), 1, $right);
518 } elseif ($action == -1 && !empty($objectname)) {
522 foreach ($permissions as $perms) {
523 if ($perms[4] === strtolower($objectname)) {
524 array_splice($permissions, array_search($perms, $permissions), 1);
527 } elseif ($action == -2 && !empty($objectname) && !empty($module)) {
530 $objectOfRights = array();
532 foreach ($permissions as $right) {
533 $objectOfRights[]= $right[4];
535 if (in_array(strtolower($objectname), $objectOfRights)) {
538 $permsToadd = array();
540 'read' =>
'Read '.$objectname.
' object of '.ucfirst($module),
541 'write' =>
'Create/Update '.$objectname.
' object of '.ucfirst($module),
542 'delete' =>
'Delete '.$objectname.
' object of '.ucfirst($module)
545 foreach ($perms as $index => $value) {
546 $permsToadd[$i][0] =
'';
547 $permsToadd[$i][1] = $value;
548 $permsToadd[$i][4] = strtolower($objectname);
549 $permsToadd[$i][5] = $index;
550 array_push($permissions, $permsToadd[$i]);
559 $count_perms = count($permissions);
560 for ($i = 0;$i<$count_perms;$i++) {
561 $permissions[$i][0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1)";
562 $permissions[$i][1] =
"\$this->rights[\$r][1] = '".$permissions[$i][1].
"'";
563 $permissions[$i][4] =
"\$this->rights[\$r][4] = '".$permissions[$i][4].
"'";
564 $permissions[$i][5] =
"\$this->rights[\$r][5] = '".$permissions[$i][5].
"';\n\t\t";
567 $perms_grouped = array();
568 foreach ($permissions as $perms) {
570 if (!isset($perms_grouped[$object])) {
571 $perms_grouped[$object] = [];
573 $perms_grouped[$object][] = $perms;
576 $permissions = $perms_grouped;
581 foreach ($permissions as &$object) {
584 foreach ($object as &$obj) {
585 if (str_contains($obj[5],
'read')) {
586 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 0 + 1)";
587 } elseif (str_contains($obj[5],
'write')) {
588 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 1 + 1)";
589 } elseif (str_contains($obj[5],
'delete')) {
590 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + 2 + 1)";
592 $obj[0] =
"\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', (".$o.
" * 10) + ".$p.
" + 1)";
596 usort($object,
'compareFirstValue');
601 foreach ($permissions as $perms) {
602 foreach ($perms as $per) {
603 $rights[] = implode(
";\n\t\t", $per);
604 $rights[] =
"\$r++;\n\t\t";
607 $rights_str = implode(
"", $rights);
611 dolReplaceInFile($file, array(
'/* BEGIN MODULEBUILDER PERMISSIONS */' =>
'/* BEGIN MODULEBUILDER PERMISSIONS */'.
"\n\t\t".$rights_str));
629 $attributesUnique = array (
'label',
'type',
'arrayofkeyval',
'notnull',
'default',
'index',
'foreignkey',
'position',
'enabled',
'visible',
'noteditable',
'alwayseditable',
'searchall',
'isameasure',
'css',
'cssview',
'csslist',
'help',
'showoncombobox',
'validate',
'comment',
'picto' );
631 $start =
"public \$fields=array(";
635 $lines = file($file);
637 foreach ($lines as $i => $line) {
638 if (strpos($line, $start) !==
false) {
640 while (($line = $lines[++$i]) !==
false) {
641 if (strpos($line, $end) !==
false) {
650 $table =
"== DATA SPECIFICATIONS\n";
651 $table .=
"=== Table of fields with properties for object *$objectname* : \n";
652 $table .=
"[options='header',grid=rows,frame=topbot,width=100%,caption=Organisation]\n";
656 foreach ($attributesUnique as $attUnique) {
657 $table .=
"|".$attUnique;
660 foreach ($keys as $string) {
661 $string = trim($string,
"'");
662 $string = rtrim($string,
",");
663 $array = eval(
"return [$string];");
666 if (!is_array($array)) {
670 $field = array_keys($array);
671 $values = array_values($array)[0];
674 foreach ($attributesUnique as $attUnique) {
675 if (!array_key_exists($attUnique, $values)) {
676 $values[$attUnique] =
'';
680 $table .=
"|*" . $field[0] .
"*|";
681 $table .= implode(
"|", $values) .
"\n";
685 $table .=
"__ end table for object $objectname\n";
687 $writeInFile =
dolReplaceInFile($destfile, array(
'== DATA SPECIFICATIONS' => $table));
688 if ($writeInFile<0) {
703 $start =
"== Table of fields and their properties for object *".ucfirst($objectname).
"* : ";
704 $end =
"__ end table for object ".ucfirst($objectname);
705 $str = file_get_contents($file);
706 $search =
'/' . preg_quote($start,
'/') .
'(.*?)' . preg_quote($end,
'/') .
'/s';
707 $new_contents = preg_replace($search,
'', $str);
708 file_put_contents($file, $new_contents);
722 $lines = file($file);
724 foreach ($lines as $i => $line) {
725 if (strpos($line, $start) !==
false) {
727 while (($line = $lines[++$i]) !==
false) {
728 if (strpos($line, $end) !==
false) {
736 $content = implode(
"", $keys);
750 $start =
'/* BEGIN MODULEBUILDER PERMISSIONS */';
751 $end =
'/* END MODULEBUILDER PERMISSIONS */';
753 if (empty($content)) {
757 $string =
"[options='header',grid=rows,width=60%,caption=Organisation]\n";
760 $header = array($langs->trans(
'Objects'),$langs->trans(
'Permission'));
761 foreach ($header as $h) {
766 $array = explode(
";", $content);
767 $permissions = array_filter($array);
769 $permissions = str_replace(
'$r++', 1, $permissions);
772 foreach ($permissions as $i => $element) {
774 unset($permissions[$i]);
776 if (str_contains($element,
'$this->numero')) {
777 unset($permissions[$i]);
779 if (str_contains($element,
'$this->rights[$r][5]')) {
780 unset($permissions[$i]);
784 foreach ($permissions as $key => $element) {
785 $element = str_replace(
" '",
'', $element);
786 $element = trim($element,
"'");
787 $permsN[] = substr($element, strpos($element,
"=")+1);
794 while ($index < count($permsN)) {
795 $temp_array = [$permsN[$index], $permsN[$index + 1]];
796 $final_array[] = $temp_array;
801 foreach ($final_array as $subarray) {
805 $result[$key][] = $subarray;
807 foreach ($result as $i => $pems) {
808 $string .=
"|*".$i.
"*|";
809 foreach ($pems as $tab) {
810 $string .= $tab[0].
" , ";
815 $string .=
"\n|===\n";
816 $write =
dolReplaceInFile($destfile, array(
'__DATA_PERMISSIONS__'=> $string));
832 if (!file_exists($file)) {
835 $content = file($file);
836 $includeClass =
"dol_include_once('/mymodule/class/myobject.class.php');";
837 $props =
"public \$myobject;";
838 $varcomented =
"@var MyObject \$myobject {@type MyObject}";
839 $constructObj =
"\$this->myobject = new MyObject(\$this->db);";
842 foreach ($content as $lineNumber => &$lineContent) {
843 if (strpos($lineContent, $varcomented) !==
false) {
845 foreach ($objects as $object) {
846 $lineContent .=
"\t * @var ".$object.
" \$".strtolower($object).
" {@type ".$object.
"}". PHP_EOL;
850 if (strpos($lineContent, $props) !==
false) {
852 foreach ($objects as $object) {
853 $lineContent .=
"\tpublic \$".strtolower($object).
";". PHP_EOL;
856 if (strpos($lineContent, $constructObj) !==
false) {
858 foreach ($objects as $object) {
859 $lineContent .=
"\t\t\$this->".strtolower($object).
" = new ".$object.
"(\$this->db);". PHP_EOL;
862 if (strpos($lineContent, $includeClass) !==
false) {
864 foreach ($objects as $object) {
865 $lineContent .=
"dol_include_once('/".strtolower($modulename).
"/class/".strtolower($object).
".class.php');". PHP_EOL;
869 $allContent = implode(
"", $content);
870 file_put_contents($file, $allContent);
873 $allContent =
getFromFile($file,
'/*begin methods CRUD*/',
'/*end methods CRUD*/');
874 foreach ($objects as $object) {
875 $contentReplaced =str_replace([
"myobject",
"MyObject"], [strtolower($object),$object], $allContent);
876 dolReplaceInFile($file, array(
'/*end methods CRUD*/' =>
'/*CRUD FOR '.strtoupper($object).
'*/'.
"\n".$contentReplaced.
"\n\t".
'/*END CRUD FOR '.strtoupper($object).
'*/'.
"\n\t".
'/*end methods CRUD*/'));
878 dolReplaceInFile($file, array($allContent =>
'',
'MyModule' => ucfirst($modulename)));
891 $begin =
'/*CRUD FOR '.strtoupper($objectname).
'*/';
892 $end =
'/*END CRUD FOR '.strtoupper($objectname).
'*/';
893 $includeClass =
"dol_include_once('/".strtolower($modulename).
"/class/".strtolower($objectname).
".class.php');";
894 $varcomentedDel =
"\t * @var ".$objectname.
" \$".strtolower($objectname).
" {@type ".$objectname.
"}";
895 $propsDel =
"\tpublic \$".strtolower($objectname).
";";
896 $constructObjDel =
"\t\t\$this->".strtolower($objectname).
" = new ".$objectname.
"(\$this->db);";
898 if (!file_exists($file)) {
901 $content = file($file);
903 foreach ($content as $lineNumber => &$lineContent) {
904 if (strpos($lineContent, $includeClass) !==
false) {
907 if (strpos($lineContent, $varcomentedDel) !==
false) {
910 if (strpos($lineContent, $propsDel) !==
false) {
913 if (strpos($lineContent, $constructObjDel) !==
false) {
917 $allContent = implode(
"", $content);
918 file_put_contents($file, $allContent);
941 if (!file_exists($file)) {
944 if ($action == 0 && !empty($key)) {
946 array_splice($menus, array_search($menus[$key], $menus), 1);
947 } elseif ($action == 1) {
949 array_push($menus, $menuWantTo);
950 } elseif ($action == 2 && !empty($key) && !empty($menuWantTo)) {
954 foreach ($menus as $index => $menu) {
955 if ($index !== $key) {
956 if ($menu[
'type'] === $menuWantTo[
'type']) {
957 if (strcasecmp(str_replace(
' ',
'', $menu[
'titre']), str_replace(
' ',
'', $menuWantTo[
'titre'])) === 0) {
960 if (strcasecmp(str_replace(
' ',
'', $menu[
'url']), str_replace(
' ',
'', $menuWantTo[
'url'])) === 0) {
967 $menus[$key] = $menuWantTo;
971 } elseif ($action == -1 && !empty($menuWantTo)) {
973 foreach ($menus as $index => $menu) {
974 if ((strpos(strtolower($menu[
'fk_menu']), strtolower($menuWantTo)) !==
false) || (strpos(strtolower($menu[
'leftmenu']), strtolower($menuWantTo)) !==
false)) {
975 array_splice($menus, array_search($menu, $menus), 1);
983 $beginMenu =
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */';
984 $endMenu =
'/* END MODULEBUILDER LEFTMENU MYOBJECT */';
985 $allMenus =
getFromFile($file, $beginMenu, $endMenu);
990 foreach ($menus as $index =>$menu) {
991 $menu[
'position'] =
"1000 + \$r";
992 if ($menu[
'type'] ===
'left') {
993 $start =
"\t\t".
'/* LEFTMENU '.strtoupper($menu[
'titre']).
' */';
994 $end =
"\t\t".
'/* END LEFTMENU '.strtoupper($menu[
'titre']).
' */';
996 $next_val = $menus[$index + 1];
997 $str_menu .= $start.
"\n";
998 $str_menu.=
"\t\t\$this->menu[\$r++]=array(\n";
999 $str_menu.=
"\t\t\t 'fk_menu' =>'".$menu[
'fk_menu'].
"',\n";
1000 $str_menu.=
"\t\t\t 'type' =>'".$menu[
'type'].
"',\n";
1001 $str_menu.=
"\t\t\t 'titre' =>'".$menu[
'titre'].
"',\n";
1002 $str_menu.=
"\t\t\t 'mainmenu' =>'".$menu[
'mainmenu'].
"',\n";
1003 $str_menu.=
"\t\t\t 'leftmenu' =>'".$menu[
'leftmenu'].
"',\n";
1004 $str_menu.=
"\t\t\t 'url' =>'".$menu[
'url'].
"',\n";
1005 $str_menu.=
"\t\t\t 'langs' =>'".$menu[
'langs'].
"',\n";
1006 $str_menu.=
"\t\t\t 'position' =>".$menu[
'position'].
",\n";
1007 $str_menu.=
"\t\t\t 'enabled' =>'".$menu[
'enabled'].
"',\n";
1008 $str_menu.=
"\t\t\t 'perms' =>'".$menu[
'perms'].
"',\n";
1009 $str_menu.=
"\t\t\t 'target' =>'".$menu[
'target'].
"',\n";
1010 $str_menu.=
"\t\t\t 'user' =>".$menu[
'user'].
",\n";
1011 $str_menu.=
"\t\t);\n";
1013 if ($val_actuel[
'leftmenu'] !== $next_val[
'leftmenu']) {
1014 $str_menu .= $end.
"\n";
1019 dolReplaceInFile($file, array($beginMenu => $beginMenu.
"\n".$str_menu.
"\n"));
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_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)
deletePropsFromDoc($file, $objectname)
Delete property from documentation if we delete object.
writePermsInAsciiDoc($file, $destfile)
Write all permissions of each object in AsciiDoc format.
reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null, $moduletype='external')
Save data into a memory area shared by all users, all sessions on server.
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.