40 function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
'', $addfieldentry = array(), $delfieldentry =
'')
44 if (empty($objectname))
return -1;
45 if (empty($readdir)) $readdir = $destdir;
47 if (!empty($addfieldentry[
'arrayofkeyval']) && !is_array($addfieldentry[
'arrayofkeyval']))
49 dol_print_error(
'',
'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
54 if (is_array($addfieldentry) && count($addfieldentry) > 0)
56 if (empty($addfieldentry[
'name']))
58 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Name")), null,
'errors');
61 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|real|date|datetime|timestamp)$/', $addfieldentry[
'type']))
69 setEventMessages($langs->trans(
'BadValueForType', $objectname), null,
'errors');
74 $pathoffiletoeditsrc = $readdir.
'/class/'.strtolower($objectname).
'.class.php';
75 $pathoffiletoedittarget = $destdir.
'/class/'.strtolower($objectname).
'.class.php'.($readdir != $destdir ?
'.new' :
'');
78 $langs->load(
"errors");
79 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc), null,
'errors');
87 include_once $pathoffiletoeditsrc;
88 if (class_exists($objectname)) $object =
new $objectname($db);
92 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
95 $contentclass = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
98 if (count($object->fields))
100 if (is_array($addfieldentry) && count($addfieldentry))
102 $name = $addfieldentry[
'name'];
103 unset($addfieldentry[
'name']);
105 $object->fields[$name] = $addfieldentry;
107 if (!empty($delfieldentry))
109 $name = $delfieldentry;
110 unset($object->fields[$name]);
117 $texttoinsert =
'// BEGIN MODULEBUILDER PROPERTIES'.
"\n";
118 $texttoinsert .=
"\t".
''.
"\n";
121 $texttoinsert .=
"\t".
'public $fields=array('.
"\n";
123 if (count($object->fields))
125 foreach ($object->fields as $key => $val)
128 $texttoinsert .=
"\t\t'".$key.
"' => array('type'=>'".$val[
'type'].
"', 'label'=>'".$val[
'label'].
"',";
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 ($val[
'noteditable']) $texttoinsert .=
" 'noteditable'=>'".$val[
'noteditable'].
"',";
134 if ($val[
'default'] || $val[
'default'] ===
'0') $texttoinsert .=
" 'default'=>'".$val[
'default'].
"',";
135 if ($val[
'index']) $texttoinsert .=
" 'index'=>".$val[
'index'].
",";
136 if ($val[
'foreignkey']) $texttoinsert .=
" 'foreignkey'=>'".$val[
'foreignkey'].
"',";
137 if ($val[
'searchall']) $texttoinsert .=
" 'searchall'=>".$val[
'searchall'].
",";
138 if ($val[
'isameasure']) $texttoinsert .=
" 'isameasure'=>'".$val[
'isameasure'].
"',";
139 if ($val[
'css']) $texttoinsert .=
" 'css'=>'".$val[
'css'].
"',";
140 if ($val[
'help']) $texttoinsert .=
" 'help'=>\"".preg_replace(
'/"/',
'', $val[
'help']).
"\",";
141 if ($val[
'showoncombobox']) $texttoinsert .=
" 'showoncombobox'=>'".$val[
'showoncombobox'].
"',";
142 if ($val[
'disabled']) $texttoinsert .=
" 'disabled'=>'".$val[
'disabled'].
"',";
143 if ($val[
'autofocusoncreate']) $texttoinsert .=
" 'autofocusoncreate'=>'".$val[
'autofocusoncreate'].
"',";
144 if ($val[
'arrayofkeyval'])
146 $texttoinsert .=
" 'arrayofkeyval'=>array(";
148 foreach ($val[
'arrayofkeyval'] as $key2 => $val2)
150 if ($i) $texttoinsert .=
", ";
151 $texttoinsert .=
"'".$key2.
"'=>'".$val2.
"'";
154 $texttoinsert .=
"),";
156 if ($val[
'comment']) $texttoinsert .=
" 'comment'=>\"".preg_replace(
'/"/',
'', $val[
'comment']).
"\"";
158 $texttoinsert .=
"),\n";
162 $texttoinsert .=
"\t".
');'.
"\n";
165 if (count($object->fields))
169 foreach ($object->fields as $key => $val)
173 $texttoinsert .=
"\t".
'public $'.$key.
";";
178 $texttoinsert .=
"\n";
182 $texttoinsert .=
"\t".
'// END MODULEBUILDER PROPERTIES';
186 $contentclass = preg_replace(
'/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
188 dol_mkdir(dirname($pathoffiletoedittarget));
191 file_put_contents(
dol_osencode($pathoffiletoedittarget), $contentclass);
192 @chmod($pathoffiletoedittarget, octdec($newmask));
197 print $e->getMessage();
215 function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir =
'', $object = null, $moduletype =
'external')
221 if (empty($objectname))
return -1;
222 if (empty($readdir)) $readdir = $destdir;
224 $pathoffiletoclasssrc = $readdir.
'/class/'.strtolower($objectname).
'.class.php';
227 if ($moduletype ==
'internal') {
228 $pathoffiletoeditsrc = $readdir.
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
229 $pathoffiletoedittarget = $destdir.
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql'.($readdir != $destdir ?
'.new' :
'');
231 $pathoffiletoeditsrc = $readdir.
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql';
232 $pathoffiletoedittarget = $destdir.
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.sql'.($readdir != $destdir ?
'.new' :
'');
237 $langs->load(
"errors");
238 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc), null,
'errors');
244 if (!is_object($object))
246 include_once $pathoffiletoclasssrc;
247 if (class_exists($objectname)) $object =
new $objectname($db);
252 print $e->getMessage();
256 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
258 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
261 $texttoinsert =
'-- BEGIN MODULEBUILDER FIELDS'.
"\n";
262 if (count($object->fields))
264 foreach ($object->fields as $key => $val)
268 $type = $val[
'type'];
269 $type = preg_replace(
'/:.*$/',
'', $type);
271 if ($type ==
'html') $type =
'text';
272 elseif ($type ==
'price') $type = '
double';
273 elseif (in_array($type, array('link', 'sellist', 'duration'))) $type = 'integer';
274 $texttoinsert .= "\t".$key." ".$type;
275 if ($key == '
rowid') $texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY';
276 if ($key == 'entity') $texttoinsert .= ' DEFAULT 1';
278 if ($val[
'default'] !=
'')
280 if (preg_match(
'/^null$/i', $val[
'default'])) $texttoinsert .=
" DEFAULT NULL";
281 elseif (preg_match(
'/varchar/', $type)) $texttoinsert .= " DEFAULT '".$db->escape($val['default'])."'";
282 else $texttoinsert .= (($val['default'] > 0) ? ' DEFAULT '.$val['default'] : '');
285 $texttoinsert .= (($val['notnull'] > 0) ? ' NOT NULL' : '');
286 if ($i < count($object->
fields)) $texttoinsert .= ", ";
287 $texttoinsert .= "\
n";
290 $texttoinsert .= "\t".'-- END MODULEBUILDER FIELDS';
292 $contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
294 $result = file_put_contents($pathoffiletoedittarget, $contentsql);
297 @chmod($pathoffiletoedittarget, octdec($newmask));
303 if ($moduletype ==
'internal') {
304 $pathoffiletoeditsrc = $readdir.
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.key.sql';
305 $pathoffiletoedittarget = $destdir.
'/../install/mysql/tables/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.key.sql'.($readdir != $destdir ?
'.new' :
'');
307 $pathoffiletoeditsrc = $destdir.
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.key.sql';
308 $pathoffiletoedittarget = $destdir.
'/sql/llx_'.strtolower($module).
'_'.strtolower($objectname).
'.key.sql'.($readdir != $destdir ?
'.new' :
'');
311 $contentsql = file_get_contents(
dol_osencode($pathoffiletoeditsrc),
'r');
314 $texttoinsert =
'-- BEGIN MODULEBUILDER INDEXES'.
"\n";
315 if (count($object->fields))
317 foreach ($object->fields as $key => $val)
320 if (!empty($val[
'index']))
322 $texttoinsert .=
"ALTER TABLE llx_".strtolower($module).
'_'.strtolower($objectname).
" ADD INDEX idx_".strtolower($module).
'_'.strtolower($objectname).
"_".$key.
" (".$key.
");";
323 $texttoinsert .=
"\n";
325 if (!empty($val[
'foreignkey']))
327 $tmp = explode(
'.', $val[
'foreignkey']);
328 if (!empty($tmp[0]) && !empty($tmp[1]))
330 $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].
");";
331 $texttoinsert .=
"\n";
336 $texttoinsert .=
'-- END MODULEBUILDER INDEXES';
338 $contentsql = preg_replace(
'/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql);
340 dol_mkdir(dirname($pathoffiletoedittarget));
342 $result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
345 @chmod($pathoffiletoedittarget, octdec($newmask));
350 return $error ? -1 : 1;
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
dol_is_file($pathoffile)
Return if path is 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...
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $_SERVER["PHP_SELF"] n
Edit parameters.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)