diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index c3c74cd9e697a..0882c22a97a0a 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -175,10 +175,14 @@ protected function _filterObjectProperties($object, $properties) // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** - * Clean sensible object datas + * Clean sensitive object data + * @phpstan-template T of Object * * @param Object $object Object to clean * @return Object Object with cleaned properties + * + * @phpstan-param T $object + * @phpstan-return T */ protected function _cleanObjectDatas($object) { diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 98d3b66f34a01..81e1a2fceba98 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -26,14 +26,14 @@ /** * Regenerate files .class.php * - * @param string $destdir Directory - * @param string $module Module name - * @param string $objectname Name of object - * @param string $newmask New mask - * @param string $readdir Directory source (use $destdir when not defined) + * @param string $destdir Directory + * @param string $module Module name + * @param string $objectname Name of object + * @param string $newmask New mask + * @param string $readdir Directory source (use $destdir when not defined) * @param array{}|array{name:string,key:string,type:string,label:string,picot?:string,enabled:int<0,1>,notnull:int<0,1>,position:int,visible:int,noteditable?:int<0,1>,alwayseditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int<0,1>,css?:string,cssview?:string,csslist?:string,help?:string,showoncombobox?:int<0,1>,disabled?:int<0,1>,autofocusoncreate?:int<0,1>,arrayofkeyval?:array,validate?:int<0,1>,comment?:string} $addfieldentry Array of 1 field entry to add - * @param string $delfieldentry Id of field to remove - * @return int<-7,-1>|CommonObject Return integer <=0 if KO, Object if OK + * @param string $delfieldentry Id of field to remove + * @return int<-7,-1>|CommonObject Return integer <=0 if KO, Object if OK * @see rebuildObjectSql() */ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = '', $addfieldentry = array(), $delfieldentry = '') @@ -79,7 +79,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = return -3; } - //$pathoffiletoedittmp=$destdir.'/class/'.strtolower($objectname).'.class.php.tmp'; + //$pathoffiletoedittmp = $destdir.'/class/'.strtolower($objectname).'.class.php.tmp'; //dol_delete_file($pathoffiletoedittmp, 0, 1, 1); try { @@ -116,67 +116,68 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $i = 0; $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; $texttoinsert .= "\t".'/**'."\n"; - $texttoinsert .= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; + $texttoinsert .= "\t".' * @inheritdoc'."\n"; + $texttoinsert .= "\t".' * Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; $texttoinsert .= "\t".' */'."\n"; - $texttoinsert .= "\t".'public $fields=array('."\n"; + $texttoinsert .= "\t".'public $fields = array('."\n"; if (count($object->fields)) { foreach ($object->fields as $key => $val) { $i++; $texttoinsert .= "\t\t".'"'.$key.'" => array('; - $texttoinsert .= '"type"=>"'.dol_escape_php($val['type']).'",'; - $texttoinsert .= ' "label"=>"'.dol_escape_php($val['label']).'",'; + $texttoinsert .= '"type" => "'.dol_escape_php($val['type']).'",'; + $texttoinsert .= ' "label" => "'.dol_escape_php($val['label']).'",'; if (!empty($val['picto'])) { - $texttoinsert .= ' "picto"=>"'.dol_escape_php($val['picto']).'",'; + $texttoinsert .= ' "picto" => "'.dol_escape_php($val['picto']).'",'; } - $texttoinsert .= ' "enabled"=>"'.($val['enabled'] !== '' ? dol_escape_php($val['enabled']) : 1).'",'; - $texttoinsert .= " 'position'=>".($val['position'] !== '' ? (int) $val['position'] : 50).","; - $texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : (int) $val['notnull']).","; - $texttoinsert .= ' "visible"=>"'.($val['visible'] !== '' ? dol_escape_js($val['visible']) : -1).'",'; + $texttoinsert .= ' "enabled" => "'.($val['enabled'] !== '' ? dol_escape_php($val['enabled']) : 1).'",'; + $texttoinsert .= " 'position' => ".($val['position'] !== '' ? (int) $val['position'] : 50).","; + $texttoinsert .= " 'notnull' => ".(empty($val['notnull']) ? 0 : (int) $val['notnull']).","; + $texttoinsert .= ' "visible" => "'.($val['visible'] !== '' ? dol_escape_js($val['visible']) : -1).'",'; if (!empty($val['noteditable'])) { - $texttoinsert .= ' "noteditable"=>"'.dol_escape_php($val['noteditable']).'",'; + $texttoinsert .= ' "noteditable" => "'.dol_escape_php($val['noteditable']).'",'; } if (!empty($val['alwayseditable'])) { - $texttoinsert .= ' "alwayseditable"=>"'.dol_escape_php($val['alwayseditable']).'",'; + $texttoinsert .= ' "alwayseditable" => "'.dol_escape_php($val['alwayseditable']).'",'; } if (array_key_exists('default', $val) && (!empty($val['default']) || $val['default'] === '0')) { - $texttoinsert .= ' "default"=>"'.dol_escape_php($val['default']).'",'; + $texttoinsert .= ' "default" => "'.dol_escape_php($val['default']).'",'; } if (!empty($val['index'])) { - $texttoinsert .= ' "index"=>"'.(int) $val['index'].'",'; + $texttoinsert .= ' "index" => "'.(int) $val['index'].'",'; } if (!empty($val['foreignkey'])) { - $texttoinsert .= ' "foreignkey"=>"'.(int) $val['foreignkey'].'",'; + $texttoinsert .= ' "foreignkey" => "'.(int) $val['foreignkey'].'",'; } if (!empty($val['searchall'])) { - $texttoinsert .= ' "searchall"=>"'.(int) $val['searchall'].'",'; + $texttoinsert .= ' "searchall" => "'.(int) $val['searchall'].'",'; } if (!empty($val['isameasure'])) { - $texttoinsert .= ' "isameasure"=>"'.(int) $val['isameasure'].'",'; + $texttoinsert .= ' "isameasure" => "'.(int) $val['isameasure'].'",'; } if (!empty($val['css'])) { - $texttoinsert .= ' "css"=>"'.dol_escape_php($val['css']).'",'; + $texttoinsert .= ' "css" => "'.dol_escape_php($val['css']).'",'; } if (!empty($val['cssview'])) { - $texttoinsert .= ' "cssview"=>"'.dol_escape_php($val['cssview']).'",'; + $texttoinsert .= ' "cssview" => "'.dol_escape_php($val['cssview']).'",'; } if (!empty($val['csslist'])) { - $texttoinsert .= ' "csslist"=>"'.dol_escape_php($val['csslist']).'",'; + $texttoinsert .= ' "csslist" => "'.dol_escape_php($val['csslist']).'",'; } if (!empty($val['help'])) { - $texttoinsert .= ' "help"=>"'.dol_escape_php($val['help']).'",'; + $texttoinsert .= ' "help" => "'.dol_escape_php($val['help']).'",'; } if (!empty($val['showoncombobox'])) { - $texttoinsert .= ' "showoncombobox"=>"'.(int) $val['showoncombobox'].'",'; + $texttoinsert .= ' "showoncombobox" => "'.(int) $val['showoncombobox'].'",'; } if (!empty($val['disabled'])) { - $texttoinsert .= ' "disabled"=>"'.(int) $val['disabled'].'",'; + $texttoinsert .= ' "disabled" => "'.(int) $val['disabled'].'",'; } if (!empty($val['autofocusoncreate'])) { - $texttoinsert .= ' "autofocusoncreate"=>"'.(int) $val['autofocusoncreate'].'",'; + $texttoinsert .= ' "autofocusoncreate" => "'.(int) $val['autofocusoncreate'].'",'; } if (!empty($val['arrayofkeyval'])) { - $texttoinsert .= ' "arrayofkeyval"=>array('; + $texttoinsert .= ' "arrayofkeyval" => array('; $i = 0; foreach ($val['arrayofkeyval'] as $key2 => $val2) { if ($i) { @@ -188,10 +189,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $texttoinsert .= '),'; } if (!empty($val['validate'])) { - $texttoinsert .= ' "validate"=>"'.(int) $val['validate'].'",'; + $texttoinsert .= ' "validate" => "'.(int) $val['validate'].'",'; } if (!empty($val['comment'])) { - $texttoinsert .= ' "comment"=>"'.dol_escape_php($val['comment']).'"'; + $texttoinsert .= ' "comment" => "'.dol_escape_php($val['comment']).'"'; } $texttoinsert .= "),\n"; @@ -203,16 +204,16 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = //print ($texttoinsert);exit; if (count($object->fields)) { - //$typetotypephp=array('integer'=>'integer', 'duration'=>'integer', 'varchar'=>'string'); + //$typetotypephp = array('integer' => 'integer', 'duration' => 'integer', 'varchar' => 'string'); foreach ($object->fields as $key => $val) { $i++; - //$typephp=$typetotypephp[$val['type']]; + //$typephp = $typetotypephp[$val['type']]; $texttoinsert .= "\t".'public $'.$key.";"; //if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; //if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; //$texttoinsert.= ($val['notnull']?' NOT NULL':''); - //if ($i < count($object->fields)) $texttoinsert.=";"; + //if ($i < count($object->fields)) $texttoinsert. = ";"; $texttoinsert .= "\n"; } } @@ -245,14 +246,14 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = /** * Save data into a memory area shared by all users, all sessions on server * - * @param string $destdir Directory - * @param string $module Module name - * @param string $objectname Name of object - * @param string $newmask New mask - * @param string $readdir Directory source (use $destdir when not defined) - * @param Object $object If object was already loaded/known, it is pass to avoid another include and new. - * @param string $moduletype 'external' or 'internal' - * @return int Return integer <=0 if KO, >0 if OK + * @param string $destdir Directory + * @param string $module Module name + * @param string $objectname Name of object + * @param string $newmask New mask + * @param string $readdir Directory source (use $destdir when not defined) + * @param Object $object If object was already loaded/known, it is pass to avoid another include and new. + * @param string $moduletype 'external' or 'internal' + * @return int Return integer <=0 if KO, >0 if OK * @see rebuildObjectClass() */ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '', $object = null, $moduletype = 'external') @@ -430,8 +431,8 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' /** * Get list of existing objects from a directory * - * @param string $destdir Directory - * @return array|int Return integer <=0 if KO, array if OK + * @param string $destdir Directory + * @return string[]|int Return integer <=0 if KO, array if OK */ function dolGetListOfObjectClasses($destdir) { @@ -462,9 +463,9 @@ function dolGetListOfObjectClasses($destdir) /** * Function to check if comment BEGIN and END exists in modMyModule class * - * @param string $file Filename or path - * @param int $number 0 = For Menus, 1 = For permissions, 2 = For Dictionaries - * @return int 1 if OK , -1 if KO + * @param string $file Filename or path + * @param int<0,2> $number 0 = For Menus, 1 = For permissions, 2 = For Dictionaries + * @return int 1 if OK , -1 if KO */ function checkExistComment($file, $number) { @@ -507,8 +508,8 @@ function checkExistComment($file, $number) /** * Delete all permissions * - * @param string $file file with path - * @return void + * @param string $file file with path + * @return void */ function deletePerms($file) { @@ -538,10 +539,10 @@ function deletePerms($file) } /** - * Compare two value - * @param int|string $a value 1 - * @param int|string $b value 2 - * @return int less 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. + * Compare two values + * @param int|string $a value 1 + * @param int|string $b value 2 + * @return int<-1,1> <=0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. */ function compareFirstValue($a, $b) { @@ -549,25 +550,25 @@ function compareFirstValue($a, $b) } /** * Rewriting all permissions after any actions - * @param string $file filename or path - * @param array $permissions permissions existing in file - * @param int|null $key key for permission needed - * @param array{0:string,1:string}|null $right $right to update or add - * @param string|null $objectname name of object - * @param string|null $module name of module - * @param int<-2,2> $action 0 for delete, 1 for add, 2 for update, -1 when delete object completely, -2 for generate rights after add - * @return int<-1,1> 1 if OK,-1 if KO + * @param string $file filename or path + * @param array $permissions permissions existing in file + * @param ?int $key key for permission needed + * @param ?array{0:string,1:string} $right $right to update or add + * @param string $objectname name of object + * @param string $module name of module + * @param int<-2,2> $action 0 for delete, 1 for add, 2 for update, -1 when delete object completely, -2 for generate rights after add + * @return int<-1,1> 1 if OK,-1 if KO */ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action) { $error = 0; $rights = array(); - if ($action == 0) { + if ($action == 0 && $key !== null) { // delete right from permissions array array_splice($permissions, array_search($permissions[$key], $permissions), 1); } elseif ($action == 1) { array_push($permissions, $right); - } elseif ($action == 2 && !empty($right)) { + } elseif ($action == 2 && !empty($right) && $key !== null) { // update right from permissions array array_splice($permissions, array_search($permissions[$key], $permissions), 1, $right); } elseif ($action == -1 && !empty($objectname)) { @@ -624,7 +625,7 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $ foreach ($permissions as $perms) { $object = $perms[4]; if (!isset($perms_grouped[$object])) { - $perms_grouped[$object] = []; + $perms_grouped[$object] = array(); } $perms_grouped[$object][] = $perms; } @@ -656,11 +657,10 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $ //convert to string foreach ($permissions as $perms) { foreach ($perms as $per) { - $rights[] = implode(";\n\t\t", $per); - $rights[] = "\$r++;\n\t\t"; + $rights[] = implode(";\n\t\t", $per)."\$r++;\n"; } } - $rights_str = implode("", $rights); + $rights_str = implode("\t\t", $rights); // delete all permissions from file deletePerms($file); // rewrite all permissions again @@ -674,8 +674,8 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $ /** * Converts a formatted properties string into an associative array. * - * @param string $string The formatted properties string. - * @return array The resulting associative array. + * @param string $string The formatted properties string. + * @return array The resulting associative array. */ function parsePropertyString($string) { @@ -683,7 +683,7 @@ function parsePropertyString($string) // Uses a regular expression to capture keys and values preg_match_all('/\s*([^\s=>]+)\s*=>\s*([^,]+),?/', $string, $matches, PREG_SET_ORDER); - $propertyArray = []; + $propertyArray = array(); foreach ($matches as $match) { $key = trim($match[1]); @@ -718,10 +718,10 @@ function parsePropertyString($string) /** * Write all properties of the object in AsciiDoc format - * @param string $file path of the class - * @param string $objectname name of the objectClass - * @param string $destfile file where write table of properties - * @return int 1 if OK, -1 if KO + * @param string $file path of the class + * @param string $objectname name of the objectClass + * @param string $destfile file where write table of properties + * @return int 1 if OK, -1 if KO */ function writePropsInAsciiDoc($file, $objectname, $destfile) { @@ -729,7 +729,7 @@ function writePropsInAsciiDoc($file, $objectname, $destfile) // stock all properties in array $attributesUnique = array('type','label', 'enabled', 'position', 'notnull', 'visible', 'noteditable', 'index', 'default' , 'foreignkey', 'arrayofkeyval', 'alwayseditable','validate', 'searchall','comment', 'isameasure', 'css', 'cssview','csslist', 'help', 'showoncombobox','picto' ); - $start = "public \$fields=array("; + $start = "public \$fields = array("; $end = ");"; $i = 1; $keys = array(); @@ -817,9 +817,9 @@ function writePropsInAsciiDoc($file, $objectname, $destfile) /** * Delete property and permissions from documentation ascii file if we delete an object * - * @param string $file file or path - * @param string $objectname name of object wants to deleted - * @return void + * @param string $file file or path + * @param string $objectname name of object wants to deleted + * @return void */ function deletePropsAndPermsFromDoc($file, $objectname) { @@ -846,12 +846,12 @@ function deletePropsAndPermsFromDoc($file, $objectname) /** * Search a string and return all lines needed from file. Does not include line $start nor $end * - * @param string $file file for searching - * @param string $start start line if exist - * @param string $end end line if exist - * @param string $excludestart Ignore if start line is $excludestart - * @param int $includese Include start and end line - * @return string Return the lines between first line with $start and $end. "" if not found. + * @param string $file file for searching + * @param string $start start line if it exists + * @param string $end end line if it exists + * @param string $excludestart Ignore if start line is $excludestart + * @param int<0,1> $includese Include start and end line + * @return string Return the lines between first line with $start and $end. "" if not found. */ function getFromFile($file, $start, $end, $excludestart = '', $includese = 0) { @@ -889,9 +889,9 @@ function getFromFile($file, $start, $end, $excludestart = '', $includese = 0) /** * Write all permissions of each object in AsciiDoc format - * @param string $file path of the class - * @param string $destfile file where write table of permissions - * @return int<-1,1> 1 if OK, -1 if KO + * @param string $file path of the class + * @param string $destfile file where write table of permissions + * @return int<-1,1> 1 if OK, -1 if KO */ function writePermsInAsciiDoc($file, $destfile) { @@ -939,10 +939,10 @@ function writePermsInAsciiDoc($file, $destfile) array_pop($permsN); // Group permissions by Object and add it to string - $final_array = []; + $final_array = array(); $index = 0; while ($index < count($permsN)) { - $temp_array = [$permsN[$index], $permsN[$index + 1]]; + $temp_array = array($permsN[$index], $permsN[$index + 1]); $final_array[] = $temp_array; $index += 2; } @@ -974,11 +974,11 @@ function writePermsInAsciiDoc($file, $destfile) /** * Add Object in ModuleApi File * - * @param string $srcfile Source file to use as example - * @param string $file Path of modified file - * @param string[] $objects Array of objects in the module - * @param string $modulename Name of module - * @return int<-1,1> Return 1 if OK, -1 if KO + * @param string $srcfile Source file to use as example + * @param string $file Path of modified file + * @param string[] $objects Array of objects in the module + * @param string $modulename Name of module + * @return int<-1,1> Return 1 if OK, -1 if KO */ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) { @@ -1007,7 +1007,7 @@ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) } elseif (preg_match('/'.$props.'/', $lineContent)) { $lineContent = ''; foreach ($objects as $objectname) { - $lineContent .= "\tpublic \$".strtolower($objectname).";". PHP_EOL; + $lineContent .= "\t/*".PHP_EOL."\t * @var mixed TODO: set type".PHP_EOL."\t */".PHP_EOL."\tpublic \$".strtolower($objectname).";". PHP_EOL; } } elseif (preg_match('/'.$constructObj.'/', $lineContent)) { $lineContent = ''; @@ -1040,7 +1040,7 @@ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) 'myobject' => strtolower($objectname), 'MyObject' => $objectname, 'MYOBJECT' => strtoupper($objectname), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') ); $contentReplaced = make_substitutions($allContent, $arrayreplacement, null); //$contentReplaced = str_replace(["myobject","MyObject"], [strtolower($object),$object], $allContent); @@ -1060,10 +1060,10 @@ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) /** * Remove Object variables and methods from API_Module File * - * @param string $file File api module - * @param string[] $objects Array of objects in the module - * @param string $objectname Name of object want to remove - * @return int<-1,1> 1 if OK, -1 if KO + * @param string $file File api module + * @param string[] $objects Array of objects in the module + * @param string $objectname Name of object want to remove + * @return int<-1,1> 1 if OK, -1 if KO */ function removeObjectFromApiFile($file, $objects, $objectname) { @@ -1108,12 +1108,12 @@ function removeObjectFromApiFile($file, $objects, $objectname) /** - * @param string $file path of filename - * @param array $menus all menus for module - * @param mixed|null $menuWantTo menu get for do actions - * @param int|null $key key for the concerned menu - * @param int<-1,2> $action for specify what action (0 = delete perm, 1 = add perm, 2 = update perm, -1 = when we delete object) - * @return int<-1,1> 1 if OK, -1 if KO + * @param string $file path of filename + * @param array $menus all menus for module + * @param null|string|array{commentgroup:string,fk_menu:string,type:string,titre:string,mainmenu:string,leftmenu:string,url:string,langs:string,position:int,enabled:int,perms:string,target:string,user:int} $menuWantTo menu get for do actions + * @param ?int $key key for the concerned menu + * @param int<-1,2> $action for specify what action (0 = delete perm, 1 = add perm, 2 = update perm, -1 = when we delete object) + * @return int<-1,1> 1 if OK, -1 if KO */ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) { @@ -1150,7 +1150,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) } else { $errors++; } - } elseif ($action == -1 && !empty($menuWantTo)) { + } elseif ($action == -1 && !empty($menuWantTo) && is_string($menuWantTo)) { // delete menus when delete Object foreach ($menus as $index => $menu) { if ((strpos(strtolower($menu['fk_menu']), strtolower($menuWantTo)) !== false) || (strpos(strtolower($menu['leftmenu']), strtolower($menuWantTo)) !== false)) { @@ -1184,20 +1184,20 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) //var_dump(dol_escape_php($menu['perms'], 1)); exit; $str_menu .= $start."\n"; - $str_menu .= "\t\t\$this->menu[\$r++]=array(\n"; - $str_menu .= "\t\t\t 'fk_menu' => '".dol_escape_php($menu['fk_menu'], 1)."',\n"; - $str_menu .= "\t\t\t 'type' => '".dol_escape_php($menu['type'], 1)."',\n"; - $str_menu .= "\t\t\t 'titre' => '".dol_escape_php($menu['titre'], 1)."',\n"; - $str_menu .= "\t\t\t 'mainmenu' => '".dol_escape_php($menu['mainmenu'], 1)."',\n"; - $str_menu .= "\t\t\t 'leftmenu' => '".dol_escape_php($menu['leftmenu'], 1)."',\n"; - $str_menu .= "\t\t\t 'url' => '".dol_escape_php($menu['url'], 1)."',\n"; - $str_menu .= "\t\t\t 'langs' => '".dol_escape_php($menu['langs'], 1)."',\n"; - $str_menu .= "\t\t\t 'position' => ".((int) $menu['position']).",\n"; - $str_menu .= "\t\t\t 'enabled' => '".dol_escape_php($menu['enabled'], 1)."',\n"; - $str_menu .= "\t\t\t 'perms' => '".dol_escape_php($menu['perms'], 1)."',\n"; - $str_menu .= "\t\t\t 'target' => '".dol_escape_php($menu['target'], 1)."',\n"; - $str_menu .= "\t\t\t 'user' => ".((int) $menu['user']).",\n"; - $str_menu .= "\t\t\t 'object' => '".dol_escape_php($menu['object'], 1)."',\n"; + $str_menu .= "\t\t\$this->menu[\$r++] = array(\n"; + $str_menu .= "\t\t\t'fk_menu' => '".dol_escape_php($menu['fk_menu'], 1)."',\n"; + $str_menu .= "\t\t\t'type' => '".dol_escape_php($menu['type'], 1)."',\n"; + $str_menu .= "\t\t\t'titre' => '".dol_escape_php($menu['titre'], 1)."',\n"; + $str_menu .= "\t\t\t'mainmenu' => '".dol_escape_php($menu['mainmenu'], 1)."',\n"; + $str_menu .= "\t\t\t'leftmenu' => '".dol_escape_php($menu['leftmenu'], 1)."',\n"; + $str_menu .= "\t\t\t'url' => '".dol_escape_php($menu['url'], 1)."',\n"; + $str_menu .= "\t\t\t'langs' => '".dol_escape_php($menu['langs'], 1)."',\n"; + $str_menu .= "\t\t\t'position' => ".((int) $menu['position']).",\n"; + $str_menu .= "\t\t\t'enabled' => '".dol_escape_php($menu['enabled'], 1)."',\n"; + $str_menu .= "\t\t\t'perms' => '".dol_escape_php($menu['perms'], 1)."',\n"; + $str_menu .= "\t\t\t'target' => '".dol_escape_php($menu['target'], 1)."',\n"; + $str_menu .= "\t\t\t'user' => ".((int) $menu['user']).",\n"; + $str_menu .= "\t\t\t'object' => '".dol_escape_php($menu['object'], 1)."',\n"; $str_menu .= "\t\t);\n"; if (is_null($next_val) || $val_actuel['leftmenu'] !== $next_val['leftmenu']) { @@ -1215,41 +1215,41 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) /** * Updates a dictionary in a module descriptor file. * - * @param string $module The name of the module. - * @param string $file The path to the module descriptor file. - * @param array> $dicts The dictionary data to be updated. - * @return int Returns the number of replacements made in the file. + * @param string $module The name of the module. + * @param string $file The path to the module descriptor file. + * @param array{langs:string,tabname:string[],tablib:string[],tabsql:string[],tabsqlsort:string[],tabfield:string[],tabfieldvalue:string[],tabfieldinsert:string[],tabrowid:string[],tabcond:string[],tabhelp:array} $dicts The dictionary data to be updated. + * @return int Returns the number of replacements made in the file. */ function updateDictionaryInFile($module, $file, $dicts) { $isEmpty = false; - $dicData = "\t\t\$this->dictionaries=array(\n"; + $dicData = "\t\t\$this->dictionaries = array(\n"; $module = strtolower($module); foreach ($dicts as $key => $value) { if (empty($value)) { $isEmpty = true; - $dicData = "\t\t\$this->dictionaries=array();"; + $dicData = "\t\t\$this->dictionaries = array();"; break; } - $dicData .= "\t\t\t'$key'=>"; + $dicData .= "\t\t\t'$key' => "; if ($key === 'tabcond') { $conditions = array_map( /** - * @param bool|string|int $val - * @return string|int + * @param bool|string|int $val + * @return string|int */ - function ($val) use ($module) { + static function ($val) use ($module) { return is_bool($val) ? "isModEnabled('$module')" : $val; }, $value ); - $dicData .= "array(" . implode(",", $conditions) . ")"; + $dicData .= "array(" . implode(", ", $conditions) . ")"; } elseif ($key === 'tabhelp') { $helpItems = array(); foreach ($value as $helpValue) { - $helpItems[] = "array('code'=>\$langs->trans('".$helpValue['code']."'), 'field2' => 'field2tooltip')"; + $helpItems[] = "array('code' => \$langs->trans('".$helpValue['code']."'), 'field2' => 'field2tooltip')"; } $dicData .= "array(" . implode(",", $helpItems) . ")"; } else { @@ -1258,8 +1258,8 @@ function ($val) use ($module) { ",", array_map( /** - * @param string $val - * @return string + * @param string $val + * @return string */ static function ($val) { return "'$val'"; @@ -1282,16 +1282,16 @@ static function ($val) { } /** - * Creates a new dictionary table. + * Create a new dictionary table. * - * for creating a new dictionary table in Dolibarr. It generates the necessary SQL code to define the table structure, + * It generates the necessary SQL code to define the table structure, * including columns such as 'rowid', 'code', 'label', 'position', 'use_default', 'active', etc. The table name is constructed based on the provided $namedic parameter. * - * @param string $modulename The lowercase name of the module for which the dictionary table is being created. - * @param string $file The file path to the Dolibarr module builder file where the dictionaries are defined. - * @param string $namedic The name of the dictionary, which will also be used as the base for the table name. - * @param array> $dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc. - * @return int<-1,-1> Return int < 0 if error, return nothing on success + * @param string $modulename The lowercase name of the module for which the dictionary table is being created. + * @param string $file The file path to the Dolibarr module builder file where the dictionaries are defined. + * @param string $namedic The name of the dictionary, which will also be used as the base for the table name. + * @param ?array{langs:string,tabname:string[],tablib:string[],tabsql:string[],tabsqlsort:string[],tabfield:string[],tabfieldvalue:string[],tabfieldinsert:string[],tabrowid:string[],tabcond:string[],tabhelp:array} $dictionnaires An optional array containing pre-existing dictionary data, including tabname, tablib, tabsql, etc. + * @return int<-1,-1> Return int < 0 if error, return nothing on success */ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = null) { @@ -1370,9 +1370,9 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul /** * Generate Urls and add them to documentation module * - * @param string $file_api filename or path of api - * @param string $file_doc filename or path of documentation - * @return int<-1,1> -1 if KO, 1 if OK, 0 if nothing change + * @param string $file_api filename or path of api + * @param string $file_doc filename or path of documentation + * @return int<-1,1> -1 if KO, 1 if OK, 0 if nothing change */ function writeApiUrlsInDoc($file_api, $file_doc) { @@ -1384,7 +1384,7 @@ function writeApiUrlsInDoc($file_api, $file_doc) $extractUrls = explode("\n", $string); // extract urls from file - $urlValues = []; + $urlValues = array(); foreach ($extractUrls as $key => $line) { $lineWithoutTabsSpaces = preg_replace('/^[\t\s]+/', '', $line); if (strpos($lineWithoutTabsSpaces, '* @url') === 0) { @@ -1395,7 +1395,7 @@ function writeApiUrlsInDoc($file_api, $file_doc) // get urls by object $str = $_SERVER['HTTP_HOST'].'/api/index.php/'; - $groupedUrls = []; + $groupedUrls = array(); foreach ($urlValues as $url) { if (preg_match('/(?:GET|POST|PUT|DELETE) (\w+)s/', $url, $matches)) { $objectName = $matches[1]; @@ -1427,9 +1427,9 @@ function writeApiUrlsInDoc($file_api, $file_doc) /** * count directories or files in modulebuilder folder - * @param string $path path of directory - * @param int $type type of file 1= file,2=directory - * @return int|bool + * @param string $path path of directory + * @param int<1,2> $type type of file 1= file,2=directory + * @return int|false False on failure (path is not a directory) */ function countItemsInDirectory($path, $type = 1) { diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 7a8d2d86f44f3..c9cac1a186f8e 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003-2004 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -390,6 +391,7 @@ public static function getEmailingSelectorsList($forcedir = null) $objMod = new $modName($db); if (is_object($objMod)) { + '@phan-var-force ModeleBoxes $objMod'; // Define disabledbyname and disabledbymodule $disabledbyname = 0; $disabledbymodule = 0; // TODO Set to 2 if module is not enabled @@ -400,7 +402,7 @@ public static function getEmailingSelectorsList($forcedir = null) $disabledbyname = 1; } - // We set info of modules + // We set info of modules @phan-suppress-next-line PhanUndeclaredProperty $widget[$j]['picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ? img_object('', 'generic') : $objMod->boximg) : img_object('', $objMod->picto)); $widget[$j]['file'] = $files[$key]; $widget[$j]['fullpath'] = $fullpath[$key]; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 94e4347a3bc81..516b301dd903b 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -83,6 +83,7 @@ $family = GETPOST('family', 'alpha'); $picto = GETPOST('idpicto', 'alpha'); $idmodule = GETPOST('idmodule', 'alpha'); +$format = ''; // Prevent undefined in css tab // Security check if (!isModEnabled('modulebuilder')) { @@ -216,12 +217,27 @@ } +/** + * @param User $user User to produce the copyright notice for. + * + * @return string String to be used as replacement after Copyright (C) + */ +function getLicenceHeader($user) +{ + $licInfo = $user->getFullName($langs); + $emailTabs = str_repeat("\t", (int) (max(0, (31 - mb_strlen($licInfo)) / 4))); + $licInfo .= ($user->email ? $emailTabs.'<'.$user->email.'>' : ''); + $licInfo = dol_print_date($now, '%Y')."\t\t".$licInfo; + return $licInfo; +} + /* * Actions */ if ($dirins && $action == 'initmodule' && $modulename) { $modulename = ucfirst($modulename); // Force first letter in uppercase + $destdir = '/not_set/'; if (preg_match('/[^a-z0-9_]/i', $modulename)) { $error++; @@ -336,6 +352,8 @@ // Edit PHP files if (!$error) { $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1); + + $licInfo = getLicenceHeader($user); foreach ($listofphpfilestoedit as $phpfileval) { //var_dump($phpfileval['fullname']); $arrayreplacement = array( @@ -347,7 +365,8 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''), + '---Put here your own copyright and developer email---' => $licInfo, + '---Replace with your own copyright and developer email---' => $licInfo, 'Editor name' => $editorname, 'https://www.example.com' => $editorurl, '$this->version = \'1.0\'' => '$this->version = \''.$version.'\'', @@ -357,7 +376,7 @@ ); if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) { - $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR'); + $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR'); } // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -394,6 +413,9 @@ } } +$destdir = '/not_set/'; // Initialize (for static analysis) +$destfile = '/not_set/'; // Initialize (for static analysis) +$srcfile = '/not_set/'; // Initialize (for static analysis) // init API, PHPUnit if ($dirins && in_array($action, array('initapi', 'initphpunit', 'initpagecontact', 'initpagedocument', 'initpagenote', 'initpageagenda')) && !empty($module)) { @@ -466,7 +488,8 @@ 'myobject' => strtolower($objectname), 'MyObject' => $objectname, 'MYOBJECT' => strtoupper($objectname), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); if ($action == 'initapi') { @@ -527,7 +550,7 @@ 'MyObject' => $objectname, 'my object' => strtolower($objectname), 'myobject' => strtolower($objectname), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); dolReplaceInFile($destfile1, $arrayreplacement); @@ -572,7 +595,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -607,7 +630,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -642,7 +665,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -677,7 +700,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -712,7 +735,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''), + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -752,7 +775,7 @@ 'Mon module' => $modulename, 'mon module' => $modulename, 'htdocs/modulebuilder/template' => strtolower($modulename), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -797,7 +820,7 @@ '__USER_FULLNAME__' => $user->getFullName($langs), '__USER_EMAIL__' => $user->email, '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'), - '---Put here your own copyright and developer email---' => dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -809,6 +832,8 @@ } +$moduledescriptorfile = '/not_set/'; + // init Doc if ($dirins && $action == 'initdoc' && !empty($module)) { dol_mkdir($dirins.'/'.strtolower($module).'/doc'); @@ -838,7 +863,7 @@ '__USER_FULLNAME__' => $user->getFullName($langs), '__USER_EMAIL__' => $user->email, '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'), - '---Put here your own copyright and developer email---' => dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition @@ -1098,14 +1123,14 @@ * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0') * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. * 'index' if we want an index in database. - * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...). + * 'foreignkey' => 'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...). * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage) - * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200' + * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview' => 'wordbreak', 'csslist' => 'tdoverflowmax200' * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. - * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar' + * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0" => "Draft","1" => "Active","-1" => "Cancel"). Note that type can be 'integer' or 'varchar' * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. * 'comment' is not used. You can store here any text of your choice. It is not used by application. * 'validate' is 1 if need to validate with $this->validateField() @@ -1113,27 +1138,27 @@ */ /*public $fields=array( - 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), - 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), - 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), - 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'), - 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'), - 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirdparty'), - 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60), - 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), - 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62), - 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), - 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), - //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502), - 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510), - 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511), - //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512), - 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000), - 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')), + 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'), + 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Reference of object'), + 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => 1, 'notnull' => 1, 'index' => 1, 'position' => 20), + 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'css' => 'minwidth200', 'help' => 'Help text', 'alwayseditable' => '1'), + 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'default' => 'null', 'position' => 40, 'searchall' => 0, 'isameasure' => 1, 'help' => 'Help text'), + 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'visible' => 1, 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'index' => 1, 'searchall' => 1, 'help' => 'LinkToThirdparty'), + 'description' => array('type' => 'text', 'label' => 'Descrption', 'enabled' => 1, 'visible' => 0, 'position' => 60), + 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 61), + 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 62), + 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500), + 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501), + //'date_valid' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 502), + 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510), + 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511), + //'fk_user_valid' => array('type' => 'integer', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 512), + 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000), + 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => 0, 'index' => 1, 'position' => 1000, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Active', -1 => 'Cancel')), );*/ $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; - $stringforproperties .= 'public $fields=array('."\n"; + $stringforproperties .= 'public $fields = array('."\n"; $i = 10; while ($obj = $db->fetch_object($_results)) { // fieldname @@ -1249,6 +1274,8 @@ // $alwayseditable if ($fieldname == 'label') { $alwayseditable = 1; + } else { + $alwayseditable = 0; } // index $index = 0; @@ -1283,36 +1310,36 @@ } // Build the property string - $stringforproperties .= "'".$obj->Field."'=>array('type'=>'".$type."', 'label'=>'".$label."',"; + $stringforproperties .= "'".$obj->Field."' => array('type' => '".$type."', 'label' => '".$label."',"; if ($default != '') { - $stringforproperties .= " 'default'=>".$default.","; + $stringforproperties .= " 'default' => ".$default.","; } - $stringforproperties .= " 'enabled'=>".$enabled.","; - $stringforproperties .= " 'visible'=>".$visible; + $stringforproperties .= " 'enabled' => ".$enabled.","; + $stringforproperties .= " 'visible' => ".$visible; if ($notnull) { - $stringforproperties .= ", 'notnull'=>".$notnull; + $stringforproperties .= ", 'notnull' => ".$notnull; } if ($alwayseditable) { - $stringforproperties .= ", 'alwayseditable'=>1"; + $stringforproperties .= ", 'alwayseditable' => 1"; } if ($fieldname == 'ref' || $fieldname == 'code') { - $stringforproperties .= ", 'showoncombobox'=>1"; + $stringforproperties .= ", 'showoncombobox' => 1"; } - $stringforproperties .= ", 'position'=>".$position; + $stringforproperties .= ", 'position' => ".$position; if ($index) { - $stringforproperties .= ", 'index'=>".$index; + $stringforproperties .= ", 'index' => ".$index; } if ($picto) { - $stringforproperties .= ", 'picto'=>'".$picto."'"; + $stringforproperties .= ", 'picto' => '".$picto."'"; } if ($css) { - $stringforproperties .= ", 'css'=>'".$css."'"; + $stringforproperties .= ", 'css' => '".$css."'"; } if ($cssview) { - $stringforproperties .= ", 'cssview'=>'".$cssview."'"; + $stringforproperties .= ", 'cssview' => '".$cssview."'"; } if ($csslist) { - $stringforproperties .= ", 'csslist'=>'".$csslist."'"; + $stringforproperties .= ", 'csslist' => '".$csslist."'"; } $stringforproperties .= "),\n"; $i += 5; @@ -1322,6 +1349,7 @@ } } + $filetogenerate = array(); // For static analysis if (!$error) { // Copy some files $filetogenerate = array( @@ -1333,14 +1361,14 @@ 'myobject_list.php' => strtolower($objectname).'_list.php', 'admin/myobject_extrafields.php' => 'admin/'.strtolower($objectname).'_extrafields.php', 'lib/mymodule_myobject.lib.php' => 'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php', - //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php', + //'test/phpunit/MyObjectTest.php' => 'test/phpunit/'.strtolower($objectname).'Test.php', 'sql/llx_mymodule_myobject.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql', 'sql/llx_mymodule_myobject.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql', 'sql/llx_mymodule_myobject_extrafields.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql', 'sql/llx_mymodule_myobject_extrafields.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql', - //'scripts/mymodule.php'=>'scripts/'.strtolower($objectname).'.php', + //'scripts/mymodule.php' => 'scripts/'.strtolower($objectname).'.php', 'class/myobject.class.php' => 'class/'.strtolower($objectname).'.class.php', - //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php', + //'class/api_mymodule.class.php' => 'class/api_'.strtolower($module).'.class.php', ); if (GETPOST('includerefgeneration', 'aZ09')) { @@ -1366,15 +1394,21 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); } } - $rights = $moduleobj->rights; + if (is_object($moduleobj)) { + $rights = $moduleobj->rights; + } else { + $rights = []; + } $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php'; $checkComment = checkExistComment($moduledescriptorfile, 1); if ($checkComment < 0) { @@ -1421,9 +1455,9 @@ // Edit the class 'class/'.strtolower($objectname).'.class.php' if (GETPOST('includerefgeneration', 'aZ09')) { - // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>'' + // Replace 'visible' => 1, 'noteditable' => 0, 'default' => '' $arrayreplacement = array( - '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'" + '/\'visible\'s*=>s*1,\s*\'noteditable\'s*=>s*0,\s*\'default\'s*=>s*\'\'/' => "'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)'" ); //var_dump($arrayreplacement);exit; //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit; @@ -1451,7 +1485,7 @@ dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } - // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);' + // TODO Update entries '$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);' // Scan for object class files @@ -1477,51 +1511,51 @@ // Regenerate left menu entry in descriptor for $objectname $stringtoadd = " - \$this->menu[\$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule', - 'type'=>'left', - 'titre'=>'MyObject', + \$this->menu[\$r++] = array( + 'fk_menu' => 'fk_mainmenu=mymodule', + 'type' => 'left', + 'titre' => 'MyObject', 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'), - 'mainmenu'=>'mymodule', - 'leftmenu'=>'myobject', - 'url'=>'/mymodule/myobject_list.php', - 'langs'=>'mymodule@mymodule', - 'position'=>1000+\$r, - 'enabled'=>'isModEnabled(\"mymodule\")', - 'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."', - 'target'=>'', - 'user'=>2, - 'object'=>'MyObject' + 'mainmenu' => 'mymodule', + 'leftmenu' => 'myobject', + 'url' => '/mymodule/myobject_list.php', + 'langs' => 'mymodule@mymodule', + 'position' => 1000 + \$r, + 'enabled' => 'isModEnabled(\"mymodule\")', + 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."', + 'target' => '', + 'user' => 2, + 'object' => 'MyObject' + ); + \$this->menu[\$r++] = array( + 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', + 'type' => 'left', + 'titre' => 'List MyObject', + 'mainmenu' => 'mymodule', + 'leftmenu' => 'mymodule_myobject_list', + 'url' => '/mymodule/myobject_list.php', + 'langs' => 'mymodule@mymodule', + 'position' => 1000 + \$r, + 'enabled' => 'isModEnabled(\"mymodule\")', + 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."', + 'target' => '', + 'user' => 2, + 'object' => 'MyObject' ); - \$this->menu[\$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', - 'type'=>'left', - 'titre'=>'List MyObject', - 'mainmenu'=>'mymodule', - 'leftmenu'=>'mymodule_myobject_list', - 'url'=>'/mymodule/myobject_list.php', - 'langs'=>'mymodule@mymodule', - 'position'=>1000+\$r, - 'enabled'=>'isModEnabled(\"mymodule\")', - 'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."', - 'target'=>'', - 'user'=>2, - 'object'=>'MyObject' - ); - \$this->menu[\$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', - 'type'=>'left', - 'titre'=>'New MyObject', - 'mainmenu'=>'mymodule', - 'leftmenu'=>'mymodule_myobject_new', - 'url'=>'/mymodule/myobject_card.php?action=create', - 'langs'=>'mymodule@mymodule', - 'position'=>1000+\$r, - 'enabled'=>'isModEnabled(\"mymodule\")', - 'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "write")' : '1')."', - 'target'=>'', - 'user'=>2, - 'object'=>'MyObject' + \$this->menu[\$r++] = array( + 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', + 'type' => 'left', + 'titre' => 'New MyObject', + 'mainmenu' => 'mymodule', + 'leftmenu' => 'mymodule_myobject_new', + 'url' => '/mymodule/myobject_card.php?action=create', + 'langs' => 'mymodule@mymodule', + 'position' => 1000 + \$r, + 'enabled' => 'isModEnabled(\"mymodule\")', + 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "write")' : '1')."', + 'target' => '', + 'user' => 2, + 'object' => 'MyObject' );"; $stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd); $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd); @@ -1536,15 +1570,21 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); } } - $menus = $moduleobj->menu; + if (is_object($moduleobj)) { + $menus = $moduleobj->menu; + } else { + $menus = array(); + } $counter = 0 ; foreach ($menus as $menu) { if ($menu['leftmenu'] == strtolower($objectname)) { @@ -1582,12 +1622,12 @@ 'htdocs/modulebuilder/template/' => strtolower($modulename), 'myobject' => strtolower($objectname), 'MyObject' => $objectname, - //'MYOBJECT'=>strtoupper($objectname), - '---Put here your own copyright and developer email---' => dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') + //'MYOBJECT' => strtoupper($objectname), + '---Replace with your own copyright and developer email---' => getLicenceHeader($user) ); if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) { - $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR'); + $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR'); } $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); @@ -1670,6 +1710,7 @@ if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -1751,6 +1792,9 @@ $error++; setEventMessages($langs->trans("ErrorObjectNotFound", $langs->transnoentities($objectname)), null, 'errors'); } + + $addfieldentry = array(); + // We click on add property if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) { if (!GETPOST('propname', 'aZ09')) { @@ -1766,6 +1810,7 @@ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); } + if (!$error && !GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) { $addfieldentry = array( 'name' => GETPOST('propname', 'aZ09'), @@ -1786,8 +1831,8 @@ 'cssview' => GETPOST('propcssview', 'alpha'), 'csslist' => GETPOST('propcsslist', 'alpha'), 'default' => GETPOST('propdefault', 'restricthtml'), - 'noteditable' => intval(GETPOSTINT('propnoteditable')), - //'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')), + 'noteditable' => GETPOSTINT('propnoteditable'), + //'alwayseditable' => GETPOSTINT('propalwayseditable'), 'validate' => GETPOSTINT('propvalidate') ); @@ -1801,8 +1846,6 @@ } } } - } else { - $addfieldentry = array(); } /*if (GETPOST('regeneratemissing')) @@ -1913,9 +1956,12 @@ dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; + if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -1994,9 +2040,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2083,6 +2131,8 @@ if (!preg_match('/^c_/', $newdicname)) { $newdicname = 'c_'.strtolower($dicname); } + } else { + $newdicname = null; } dol_include_once($pathtofile); @@ -2091,6 +2141,7 @@ if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2113,8 +2164,9 @@ $newdicname = $dicts['tabname'][GETPOSTINT('dictionnarykey') - 1]; } - //chercher la table dicname - $checkTable = $db->DDLDescTable(MAIN_DB_PREFIX.strtolower($newdicname)); + // Lookup the table dicname + $checkTable = $newdicname !== null && $db->DDLDescTable(MAIN_DB_PREFIX.strtolower($newdicname)); + if ($checkTable && $db->num_rows($checkTable) <= 0) { $error++; } @@ -2171,6 +2223,7 @@ if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2239,6 +2292,7 @@ if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2288,9 +2342,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2315,7 +2371,11 @@ //check existing object permission $counter = 0; $permsForObject = array(); - $permissions = $moduleobj->rights; + if (is_object($moduleobj)) { + $permissions = $moduleobj->rights; + } else { + $permissions = array(); + } $allObject = array(); $countPerms = count($permissions); @@ -2339,15 +2399,16 @@ } } + $rightToAdd = array(); if (!$error) { $key = $countPerms + 1; //prepare right to add - $rightToAdd = [ + $rightToAdd = array( 0 => $id, 1 => $label, 4 => $objectForPerms, 5 => $crud - ]; + ); if (isModEnabled(strtolower($module))) { $result = unActivateModule(strtolower($module)); @@ -2384,9 +2445,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrModules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2420,16 +2483,26 @@ // $label = "Delete objects of $module"; } - $permissions = $moduleobj->rights; - $key = (int) GETPOST('counter') - 1; + if (is_object($moduleobj)) { + $permissions = $moduleobj->rights; + } else { + $permissions = []; + } + $key = GETPOSTINT('counter') - 1; //get permission want to delete from permissions array - $x1 = $permissions[$key][1]; - $x2 = $permissions[$key][4]; - $x3 = $permissions[$key][5]; + if (array_key_exists($key, $permissions)) { + $x1 = $permissions[$key][1]; + $x2 = $permissions[$key][4]; + $x3 = $permissions[$key][5]; + } else { + $x1 = null; + $x2 = null; + $x3 = null; + } //check existing object permission $counter = 0; $permsForObject = array(); - $permissions = $moduleobj->rights; + // $permissions = $moduleobj->rights; // Already fetched above $firstRight = 0; $existRight = 0; $allObject = array(); @@ -2471,6 +2544,7 @@ if ($rewrite < 0) { setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings'); } else { + $rightUpdated = null; // I not set at this point reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightUpdated, '', '', 2); setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null); clearstatcache(true); @@ -2489,9 +2563,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2661,9 +2737,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2723,9 +2801,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2879,9 +2959,11 @@ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -2980,9 +3062,11 @@ dol_include_once($pathtofile); $class = 'mod'.$module; + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); @@ -3140,9 +3224,11 @@ $loadclasserrormessage .= 'Line: '.$e->getLine()."
\n"; } + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; print $e->getMessage(); @@ -3229,7 +3315,7 @@ $linktoenabledisable .= '   '.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 8px"').''; } } else { - if (!empty($moduleobj)) { + if (is_object($moduleobj)) { $linktoenabledisable .= ''; $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', false, 0, 0, '', 'classfortooltip', 1); $linktoenabledisable .= "\n"; @@ -3528,7 +3614,7 @@ print load_fiche_titre($form->textwithpicto($langs->trans("DescriptorFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofile), '', ''); - if (!empty($moduleobj)) { + if (is_object($moduleobj)) { print '
'; print '
'; print '
'; @@ -3745,7 +3831,7 @@ print ''; print ''; print ''; - print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1); + print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'newlangcode', 0, array(), 1, 0, 0, 'minwidth300', 1); print '
'; print '
'; @@ -6245,6 +6331,7 @@ function updateInputField() { print ''; print ''; + $texttoshow = null; if ($cron['jobtype'] == 'method') { $text = $langs->trans("CronClass"); $texttoshow = $langs->trans('CronModule').': '.$module.'
'; @@ -6457,10 +6544,11 @@ function updateInputField() { $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; - + $moduleobj = null; if (class_exists($class)) { try { $moduleobj = new $class($db); + '@phan-var-force DolibarrMOdules $moduleobj'; } catch (Exception $e) { $error++; dol_print_error($db, $e->getMessage()); diff --git a/htdocs/modulebuilder/template/admin/about.php b/htdocs/modulebuilder/template/admin/about.php index ecacf04f4c163..8f870de9c6f8e 100644 --- a/htdocs/modulebuilder/template/admin/about.php +++ b/htdocs/modulebuilder/template/admin/about.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; diff --git a/htdocs/modulebuilder/template/admin/myobject_extrafields.php b/htdocs/modulebuilder/template/admin/myobject_extrafields.php index 2cb2cc6882d76..76526a7ae858c 100644 --- a/htdocs/modulebuilder/template/admin/myobject_extrafields.php +++ b/htdocs/modulebuilder/template/admin/myobject_extrafields.php @@ -33,7 +33,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index f8a1e7b9041dd..b245895a586c1 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -1,7 +1,6 @@ - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -218,26 +217,26 @@ $className = $myTmpObjects[$tmpobjectkey]['class']; $tmpobject = new $className($db); + '@phan-var-force MyObject $tmpobject'; $tmpobject->initAsSpecimen(); // Search template files $file = ''; $className = ''; - $filefound = 0; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); foreach ($dirmodels as $reldir) { $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); if (file_exists($file)) { - $filefound = 1; $className = "pdf_".$modele."_".strtolower($tmpobjectkey); break; } } - if ($filefound) { + if ($className !== '') { require_once $file; $module = new $className($db); + '@phan-var-force ModelePDFMyObject $module'; '@phan-var-force ModelePDFMyObject $module'; @@ -372,8 +371,7 @@ require_once $dir.'/'.$file.'.php'; $module = new $file($db); - - '@phan-var-force CommonNumRefGenerator $module'; + '@phan-var-force ModeleNumRefMyObject $module'; // Show modules according to features level if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { @@ -416,6 +414,7 @@ $className = $myTmpObjectArray['class']; $mytmpinstance = new $className($db); + '@phan-var-force MyObject $mytmpinstance'; $mytmpinstance->initAsSpecimen(); // Info @@ -498,6 +497,7 @@ if (is_dir($dir)) { $handle = opendir($dir); if (is_resource($handle)) { + $filelist = array(); while (($file = readdir($handle)) !== false) { $filelist[] = $file; } @@ -512,7 +512,6 @@ require_once $dir.'/'.$file; $module = new $className($db); - '@phan-var-force ModelePDFMyObject $module'; $modulequalified = 1; diff --git a/htdocs/modulebuilder/template/class/actions_mymodule.class.php b/htdocs/modulebuilder/template/class/actions_mymodule.class.php index f3427bf8a8d4f..e9ec563ebebe2 100644 --- a/htdocs/modulebuilder/template/class/actions_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/actions_mymodule.class.php @@ -1,7 +1,6 @@ - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +21,7 @@ * \ingroup mymodule * \brief Example hook overload. * - * Put detailed description here. + * TODO: Write detailed description here. */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php'; @@ -43,13 +42,13 @@ class ActionsMyModule extends CommonHookActions public $error = ''; /** - * @var array Errors + * @var string[] Errors */ public $errors = array(); /** - * @var array Hook results. Propagated to $hookmanager->resArray for later reuse + * @var mixed[] Hook results. Propagated to $hookmanager->resArray for later reuse */ public $results = array(); @@ -67,7 +66,7 @@ class ActionsMyModule extends CommonHookActions /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ public function __construct($db) { @@ -78,12 +77,12 @@ public function __construct($db) /** * Execute action * - * @param array $parameters Array of parameters - * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string $action 'add', 'update', 'view' - * @return int Return integer <0 if KO, + * @param array $parameters Array of parameters + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param string $action 'add', 'update', 'view' + * @return int Return integer <0 if KO, * =0 if OK but we want to process standard actions too, - * >0 if OK and we want to replace standard actions. + * >0 if OK and we want to replace standard actions. */ public function getNomUrl($parameters, &$object, &$action) { @@ -93,13 +92,13 @@ public function getNomUrl($parameters, &$object, &$action) } /** - * Overloading the doActions function : replacing the parent's function with the one below + * Overload the doActions function : replacing the parent's function with the one below * - * @param array $parameters Hook metadatas (context, etc...) - * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string $action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code + * @param array $parameters Hook metadata (context, etc...) + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param ?string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code */ public function doActions($parameters, &$object, &$action, $hookmanager) { @@ -108,9 +107,10 @@ public function doActions($parameters, &$object, &$action, $hookmanager) $error = 0; // Error counter /* print_r($parameters); print_r($object); echo "action: " . $action; */ + // @phan-suppress-next-line PhanPluginEmptyStatementIf if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' // Do what you want here... - // You can for example load and use call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and GETPOST values. + // You can for example load and use call global vars like $fieldstosearchall to overwrite them, or update the database depending on $action and GETPOST values. } if (!$error) { @@ -125,13 +125,13 @@ public function doActions($parameters, &$object, &$action, $hookmanager) /** - * Overloading the doMassActions function : replacing the parent's function with the one below + * Overload the doMassActions function : replacing the parent's function with the one below * - * @param array $parameters Hook metadatas (context, etc...) - * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string $action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code + * @param array $parameters Hook metadata (context, etc...) + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param ?string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code */ public function doMassActions($parameters, &$object, &$action, $hookmanager) { @@ -141,6 +141,7 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager) /* print_r($parameters); print_r($object); echo "action: " . $action; */ if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' + // @phan-suppress-next-line PhanPluginEmptyStatementForeachLoop foreach ($parameters['toselect'] as $objectid) { // Do action on each object id } @@ -158,13 +159,13 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager) /** - * Overloading the addMoreMassActions function : replacing the parent's function with the one below + * Overload the addMoreMassActions function : replacing the parent's function with the one below * - * @param array $parameters Hook metadatas (context, etc...) - * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string $action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code + * @param array $parameters Hook metadata (context, etc...) + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param ?string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code */ public function addMoreMassActions($parameters, &$object, &$action, $hookmanager) { @@ -189,14 +190,14 @@ public function addMoreMassActions($parameters, &$object, &$action, $hookmanager /** - * Execute action + * Execute action before PDF (document) creation * - * @param array $parameters Array of parameters - * @param Object $object Object output on PDF - * @param string $action 'add', 'update', 'view' - * @return int Return integer <0 if KO, - * =0 if OK but we want to process standard actions too, - * >0 if OK and we want to replace standard actions. + * @param array $parameters Array of parameters + * @param CommonObject $object Object output on PDF + * @param string $action 'add', 'update', 'view' + * @return int Return integer <0 if KO, + * =0 if OK but we want to process standard actions too, + * >0 if OK and we want to replace standard actions. */ public function beforePDFCreation($parameters, &$object, &$action) { @@ -210,6 +211,7 @@ public function beforePDFCreation($parameters, &$object, &$action) dol_syslog(get_class($this).'::executeHooks action='.$action); /* print_r($parameters); print_r($object); echo "action: " . $action; */ + // @phan-suppress-next-line PhanPluginEmptyStatementIf if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' } @@ -217,14 +219,14 @@ public function beforePDFCreation($parameters, &$object, &$action) } /** - * Execute action + * Execute action after PDF (document) creation * - * @param array $parameters Array of parameters - * @param Object $pdfhandler PDF builder handler - * @param string $action 'add', 'update', 'view' - * @return int Return integer <0 if KO, - * =0 if OK but we want to process standard actions too, - * >0 if OK and we want to replace standard actions. + * @param array $parameters Array of parameters + * @param CommonDocGenerator $pdfhandler PDF builder handler + * @param string $action 'add', 'update', 'view' + * @return int Return integer <0 if KO, + * =0 if OK but we want to process standard actions too, + * >0 if OK and we want to replace standard actions. */ public function afterPDFCreation($parameters, &$pdfhandler, &$action) { @@ -238,6 +240,7 @@ public function afterPDFCreation($parameters, &$pdfhandler, &$action) dol_syslog(get_class($this).'::executeHooks action='.$action); /* print_r($parameters); print_r($object); echo "action: " . $action; */ + // @phan-suppress-next-line PhanPluginEmptyStatementIf if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2' } @@ -248,12 +251,12 @@ public function afterPDFCreation($parameters, &$pdfhandler, &$action) /** - * Overloading the loadDataForCustomReports function : returns data to complete the customreport tool + * Overload the loadDataForCustomReports function : returns data to complete the customreport tool * - * @param array $parameters Hook metadatas (context, etc...) - * @param string $action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code + * @param array $parameters Hook metadata (context, etc...) + * @param ?string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int Return integer < 0 on error, 0 on success, 1 to replace standard code */ public function loadDataForCustomReports($parameters, &$action, $hookmanager) { @@ -293,14 +296,14 @@ public function loadDataForCustomReports($parameters, &$action, $hookmanager) /** - * Overloading the restrictedArea function : check permission on an object + * Overload the restrictedArea function : check permission on an object * - * @param array $parameters Hook metadatas (context, etc...) - * @param string $action Current action (if set). Generally create or edit or null - * @param HookManager $hookmanager Hook manager propagated to allow calling another hook - * @return int Return integer <0 if KO, - * =0 if OK but we want to process standard actions too, - * >0 if OK and we want to replace standard actions. + * @param array $parameters Hook metadata (context, etc...) + * @param string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Hook manager propagated to allow calling another hook + * @return int Return integer <0 if KO, + * =0 if OK but we want to process standard actions too, + * >0 if OK and we want to replace standard actions. */ public function restrictedArea($parameters, &$action, $hookmanager) { @@ -322,13 +325,13 @@ public function restrictedArea($parameters, &$action, $hookmanager) /** * Execute action completeTabsHead * - * @param array $parameters Array of parameters - * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param string $action 'add', 'update', 'view' - * @param Hookmanager $hookmanager hookmanager - * @return int Return integer <0 if KO, - * =0 if OK but we want to process standard actions too, - * >0 if OK and we want to replace standard actions. + * @param array $parameters Array of parameters + * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param string $action 'add', 'update', 'view' + * @param Hookmanager $hookmanager Hookmanager + * @return int Return integer <0 if KO, + * =0 if OK but we want to process standard actions too, + * >0 if OK and we want to replace standard actions. */ public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager) { @@ -364,7 +367,7 @@ public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager) // return 1 to replace standard code return 1; } else { - // en V14 et + $parameters['head'] est modifiable par référence + // From V14 onwards, $parameters['head'] is modifiable by referende return 0; } } else { @@ -373,5 +376,5 @@ public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager) } } - /* Add here any other hooked methods... */ + /* Add other hook methods here... */ } diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index d41f3e2ca6687..818992d46c1ab 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -1,7 +1,6 @@ - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,6 +64,8 @@ public function __construct() * * @param int $id ID of myobject * @return Object Object with cleaned properties + * @phan-return MyObject Object with cleaned properties + * @phpstan-return MyObject Object with cleaned properties * * @phan-return MyObject * @@ -102,9 +103,9 @@ public function get($id) * @param int $page Page number * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names - * @return array Array of ordered objects - * - * @phan-return MyObject[] + * @return array Array of MyObject objects + * @phan-return array + * @phpstan-return array * * @throws RestException 403 Not allowed * @throws RestException 503 System error @@ -192,7 +193,8 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, * Create myobject object * * @param array $request_data Request data - * @phan-param array $request_data + * @phan-param array{string,mixed} $request_data + * @phpstan-param array{string,mixed} $request_data * @return int ID of myobject * * @throws RestException 403 Not allowed @@ -239,9 +241,12 @@ public function post($request_data = null) * Update myobject * * @param int $id Id of myobject to update - * @param array $request_data Datas - * @phan-param array $request_data + * @param array $request_data Data + * @phan-param mixed[] $request_data + * @phpstan-param mixed[] $request_data * @return Object Object after update + * @phan-return MyObject + * @phpstan-return MyObject * * @phan-return MyObject * @@ -300,7 +305,8 @@ public function put($id, $request_data = null) * * @param int $id MyObject ID * @return array - * @phan-return array + * @phan-return array + * @phpstan-return array * * @throws RestException 403 Not allowed * @throws RestException 404 Not found @@ -342,9 +348,11 @@ public function delete($id) * Validate fields before creating or updating object * * @param array $data Array of data to validate - * @phan-param array $data + * @phan-param array $data + * @phpstan-param array $data * @return array - * @phan-return array $data + * @phan-return array|array{} + * @phpstan-return array|array{} * * @throws RestException */ @@ -369,10 +377,14 @@ private function _validateMyObject($data) // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** - * Clean sensible object data fields + * Clean sensitive object data fields + * @phpstan-template T of Object * * @param Object $object Object to clean * @return Object Object with cleaned properties + * + * @phpstan-param T $object + * @phpstan-return T */ protected function _cleanObjectDatas($object) { diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index c20459032837d..3d24afca4f344 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -1,8 +1,7 @@ * Copyright (C) 2023-2024 Frédéric France - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -107,30 +106,28 @@ class MyObject extends CommonObject // BEGIN MODULEBUILDER PROPERTIES /** - * @var array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + * @inheritdoc + * Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. */ public $fields = array( - 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'noteditable' => 1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id', 'css' => 'left'), - 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => 1, 'index' => 1, 'position' => 10), - 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'noteditable' => 0, 'default' => '', 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 20, 'searchall' => 1, 'comment' => 'Reference of object', 'validate' => 1), - 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'help' => 'Help text', 'showoncombobox' => 2, 'validate' => 1, 'alwayseditable' => 1), - 'amount' => array('type' => 'price', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'default' => 'null', 'position' => 40, 'searchall' => 0, 'isameasure' => 1, 'help' => 'Help text for amount', 'validate' => 1), - 'qty' => array('type' => 'real', 'label' => 'Qty', 'enabled' => 1, 'visible' => 1, 'default' => '0', 'position' => 45, 'searchall' => 0, 'isameasure' => 1, 'help' => 'Help text for quantity', 'css' => 'maxwidth75imp', 'validate' => 1), - 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'picto' => 'company', 'label' => 'ThirdParty', 'visible' => 1, 'enabled' => 'isModEnabled("societe")', 'position' => 50, 'notnull' => -1, 'index' => 1, 'help' => 'OrganizationEventLinkToThirdParty', 'validate' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'), - 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'picto' => 'project', 'enabled' => 'isModEnabled("project")', 'visible' => -1, 'position' => 52, 'notnull' => -1, 'index' => 1, 'validate' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'), - 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'visible' => 3, 'position' => 60, 'validate' => 1), - 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 61, 'validate' => 1, 'cssview' => 'wordbreak'), - 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 62, 'validate' => 1, 'cssview' => 'wordbreak'), - 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500), - 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 0, 'position' => 501), - //'date_validation ' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502), - 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax150'), - 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511, 'csslist' => 'tdoverflowmax150'), - //'fk_user_valid' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512), - 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => 0, 'notnull' => 0, 'position' => 600), - 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000), - 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'notnull' => -1, 'position' => 1010), - 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => 0, 'index' => 1, 'position' => 2000, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', 9 => 'Canceled'), 'validate' => 1), + "rowid" => array("type" => "integer", "label" => "TechnicalID", "enabled" => "1", 'position' => 1, 'notnull' => 1, "visible" => "0", "noteditable" => "1", "index" => "1", "css" => "left", "comment" => "Id"), + "ref" => array("type" => "varchar(128)", "label" => "Ref", "enabled" => "1", 'position' => 20, 'notnull' => 1, "visible" => "1", "index" => "1", "searchall" => "1", "showoncombobox" => "1", "validate" => "1", "comment" => "Reference of object"), + "label" => array("type" => "varchar(255)", "label" => "Label", "enabled" => "1", 'position' => 30, 'notnull' => 0, "visible" => "1", "alwayseditable" => "1", "searchall" => "1", "css" => "minwidth300", "cssview" => "wordbreak", "help" => "Help text", "showoncombobox" => "2", "validate" => "1",), + "amount" => array("type" => "price", "label" => "Amount", "enabled" => "1", 'position' => 40, 'notnull' => 0, "visible" => "1", "default" => "null", "isameasure" => "1", "help" => "Help text for amount", "validate" => "1",), + "qty" => array("type" => "real", "label" => "Qty", "enabled" => "1", 'position' => 45, 'notnull' => 0, "visible" => "1", "default" => "0", "isameasure" => "1", "css" => "maxwidth75imp", "help" => "Help text for quantity", "validate" => "1",), + "fk_soc" => array("type" => "integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))", "label" => "ThirdParty", "picto" => "company", "enabled" => "isModEnabled('societe')", 'position' => 50, 'notnull' => -1, "visible" => "1", "index" => "1", "css" => "maxwidth500 widthcentpercentminusxx", "csslist" => "tdoverflowmax150", "help" => "OrganizationEventLinkToThirdParty", "validate" => "1",), + "fk_project" => array("type" => "integer:Project:projet/class/project.class.php:1", "label" => "Project", "picto" => "project", "enabled" => "isModEnabled('project')", 'position' => 52, 'notnull' => -1, "visible" => "-1", "index" => "1", "css" => "maxwidth500 widthcentpercentminusxx", "csslist" => "tdoverflowmax150", "validate" => "1",), + "description" => array("type" => "text", "label" => "Description", "enabled" => "1", 'position' => 60, 'notnull' => 0, "visible" => "3", "validate" => "1",), + "note_public" => array("type" => "html", "label" => "NotePublic", "enabled" => "1", 'position' => 61, 'notnull' => 0, "visible" => "0", "cssview" => "wordbreak", "validate" => "1",), + "note_private" => array("type" => "html", "label" => "NotePrivate", "enabled" => "1", 'position' => 62, 'notnull' => 0, "visible" => "0", "cssview" => "wordbreak", "validate" => "1",), + "date_creation" => array("type" => "datetime", "label" => "DateCreation", "enabled" => "1", 'position' => 500, 'notnull' => 1, "visible" => "-2",), + "tms" => array("type" => "timestamp", "label" => "DateModification", "enabled" => "1", 'position' => 501, 'notnull' => 0, "visible" => "-2",), + "fk_user_creat" => array("type" => "integer:User:user/class/user.class.php", "label" => "UserAuthor", "picto" => "user", "enabled" => "1", 'position' => 510, 'notnull' => 1, "visible" => "-2", "foreignkey" => "0", "csslist" => "tdoverflowmax150",), + "fk_user_modif" => array("type" => "integer:User:user/class/user.class.php", "label" => "UserModif", "picto" => "user", "enabled" => "1", 'position' => 511, 'notnull' => -1, "visible" => "-2", "csslist" => "tdoverflowmax150",), + "last_main_doc" => array("type" => "varchar(255)", "label" => "LastMainDoc", "enabled" => "1", 'position' => 600, 'notnull' => 0, "visible" => "0",), + "import_key" => array("type" => "varchar(14)", "label" => "ImportId", "enabled" => "1", 'position' => 1000, 'notnull' => -1, "visible" => "-2",), + "model_pdf" => array("type" => "varchar(255)", "label" => "Model pdf", "enabled" => "1", 'position' => 1010, 'notnull' => -1, "visible" => "0",), + "status" => array("type" => "integer", "label" => "Status", "enabled" => "1", 'position' => 2000, 'notnull' => 1, "visible" => "1", "index" => "1", "arrayofkeyval" => array("0" => "Draft", "1" => "Validated", "9" => "Canceled"), "validate" => "1",), ); /** @@ -162,6 +159,9 @@ class MyObject extends CommonObject * @var int Thirdparty ID */ public $socid; // both socid and fk_soc are used + /** + * @var int Thirdparty ID + */ public $fk_soc; // both socid and fk_soc are used /** @@ -230,7 +230,7 @@ class MyObject extends CommonObject /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ public function __construct(DoliDB $db) { @@ -275,9 +275,9 @@ public function __construct(DoliDB $db) /** * Create object into database * - * @param User $user User that creates - * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers - * @return int<-1,max> Return integer <0 if KO, Id of created object if OK + * @param User $user User that creates + * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers + * @return int<-1,max> Return integer <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = 0) { @@ -291,9 +291,9 @@ public function create(User $user, $notrigger = 0) /** * Clone an object into another one * - * @param User $user User that creates - * @param int $fromid Id of object to clone - * @return mixed New object created, <0 if KO + * @param User $user User that creates + * @param int $fromid Id of object to clone + * @return self|int<-1,-1> New object created, <0 if KO */ public function createFromClone(User $user, $fromid) { @@ -390,11 +390,11 @@ public function createFromClone(User $user, $fromid) /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref + * @param int $id Id object + * @param string $ref Ref * @param int<0,1> $noextrafields 0=Default to load extrafields, 1=No extrafields * @param int<0,1> $nolines 0=Default to load extrafields, 1=No extrafields - * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK + * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0) { @@ -409,7 +409,7 @@ public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0) * Load object lines in memory from the database * * @param int<0,1> $noextrafields 0=Default to load extrafields, 1=No extrafields - * @return int<1,1> Return integer <0 if KO, 0 if not found, >0 if OK + * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK */ public function fetchLines($noextrafields = 0) { @@ -432,7 +432,7 @@ public function fetchLines($noextrafields = 0) * @param string $filter Filter as an Universal Search string. * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No longer used - * @return self[]|int<-1,-1> int <0 if KO, array of pages if OK + * @return array|int<-1,-1> <0 if KO, array of pages if OK */ public function fetchAll($sortorder = '', $sortfield = '', $limit = 1000, $offset = 0, string $filter = '', $filtermode = 'AND') { @@ -752,9 +752,9 @@ public function reopen($user, $notrigger = 0) /** * getTooltipContentArray * - * @param array $params Params to construct tooltip data + * @param array $params Params to construct tooltip data * @since v18 - * @return array + * @return array{optimize?:string,picto?:string,ref?:string} */ public function getTooltipContentArray($params) { @@ -782,11 +782,11 @@ public function getTooltipContentArray($params) /** * Return a link to the object card (with optionally the picto) * - * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) - * @param string $option On what the link point to ('nolink', ...) - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param string $option On what the link point to ('nolink', ...) + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string String with URL */ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) @@ -904,9 +904,9 @@ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss /** * Return a thumb for kanban views * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. + * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) + * @param ?array $arraydata Array of data + * @return string HTML Code for Kanban thumb. */ public function getKanbanView($option = '', $arraydata = null) { @@ -947,7 +947,7 @@ public function getKanbanView($option = '', $arraydata = null) /** * Return the label of the status * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ public function getLabelStatus($mode = 0) @@ -958,8 +958,8 @@ public function getLabelStatus($mode = 0) /** * Return the label of the status * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function getLibStatut($mode = 0) { @@ -970,9 +970,9 @@ public function getLibStatut($mode = 0) /** * Return the label of a given status * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + * @param int $status Id status + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function LibStatut($status, $mode = 0) { @@ -1004,7 +1004,7 @@ public function LibStatut($status, $mode = 0) /** * Load the info information in the object * - * @param int $id Id of object + * @param int $id Id of object * @return void */ public function info($id) @@ -1056,10 +1056,10 @@ public function info($id) } /** - * Initialise object with example values + * Initialize object with example values * Id must be 0 if object instance is a specimen * - * @return int + * @return int */ public function initAsSpecimen() { @@ -1073,7 +1073,7 @@ public function initAsSpecimen() /** * Create an array of lines * - * @return array|int array of lines if OK, <0 if KO + * @return CommonObjectLine[]|int array of lines if OK, <0 if KO */ public function getLinesArray() { @@ -1094,7 +1094,7 @@ public function getLinesArray() /** * Returns the reference to the following non used object depending on the active numbering module. * - * @return string Object free reference + * @return string Object free reference */ public function getNextNumRef() { @@ -1127,6 +1127,7 @@ public function getNextNumRef() if (class_exists($classname)) { $obj = new $classname(); + '@phan-var-force ModeleNumRefMyObject $obj'; $numref = $obj->getNextValue($this); if ($numref != '' && $numref != '-1') { @@ -1149,13 +1150,13 @@ public function getNextNumRef() /** * Create a document onto disk according to template module. * - * @param string $modele Force template to use ('' to not force) - * @param Translate $outputlangs object lang a utiliser pour traduction - * @param int $hidedetails Hide details of lines - * @param int $hidedesc Hide description - * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information - * @return int 0 if KO, 1 if OK + * @param string $modele Force template to use ('' to not force) + * @param Translate $outputlangs object lang a utiliser pour traduction + * @param int<0,1> $hidedetails Hide details of lines + * @param int<0,1> $hidedesc Hide description + * @param int<0,1> $hideref Hide ref + * @param ?array $moreparams Array to provide more information + * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { @@ -1189,10 +1190,10 @@ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hided * Return validation test result for a field. * Need MAIN_ACTIVATE_VALIDATION_RESULT to be called. * - * @param array $fields Array of properties of field to show - * @param string $fieldKey Key of attribute - * @param string $fieldValue value of attribute - * @return bool Return false if fail, true on success, set $this->error for error message + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Array of properties of field to show + * @param string $fieldKey Key of attribute + * @param string $fieldValue value of attribute + * @return bool Return false if fail, true on success, set $this->error for error message */ public function validateField($fields, $fieldKey, $fieldValue) { @@ -1261,7 +1262,7 @@ class MyObjectLine extends CommonObjectLine /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ public function __construct(DoliDB $db) { diff --git a/htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php b/htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php index fc3f69c412b9d..89b562e319b86 100644 --- a/htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php +++ b/htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php @@ -1,8 +1,7 @@ * Copyright (C) 2018-2023 Frédéric France - * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php b/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php index c885b1355c606..8375a01d86724 100644 --- a/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mailings/mailing_mymodule_selector1.modules.php @@ -1,7 +1,6 @@ - * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This file is an example to follow to add your own email selector inside * the Dolibarr email tool. @@ -23,11 +22,18 @@ class mailing_mailing_mymodule_selector1 extends MailingTargets public $name = 'mailing_mymodule_selector1'; // CHANGE THIS: Put here a description of your selector module public $desc = 'Emailing target selector1'; + // CHANGE THIS: Set to 1 if selector is available for admin users only + /** + * @var int<0,1> + */ public $require_admin = 0; public $enabled = 'isModEnabled("mymodule")'; + /** + * @var string[] The modules on which this selector depends (can be "none" to not show the module. + */ public $require_module = array(); /** @@ -165,7 +171,7 @@ public function add_to_target($mailing_id) * array of SQL request that returns two field: * One called "label", One called "nb". * - * @return string[] + * @return array{}|array{label:string,nb:string} */ public function getSqlArrayForStats() { diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 256fc605c2b17..01667b14294dc 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -2,8 +2,7 @@ /* Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2018-2019 Nicolas ZABOURI * Copyright (C) 2019-2024 Frédéric France - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,7 +41,7 @@ class modMyModule extends DolibarrModules */ public function __construct($db) { - global $conf; + global $conf, $langs; $this->db = $db; @@ -189,11 +188,11 @@ public function __construct($db) /* END MODULEBUILDER TABS */ // Example: // To add a new tab identified by code tabname1 - // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@mymodule:$user->hasRight('mymodule', 'read'):/mymodule/mynewtab1.php?id=__ID__'); + // $this->tabs[] = array('data' => 'objecttype:+tabname1:Title1:mylangfile@mymodule:$user->hasRight(\'mymodule\', \'read\'):/mymodule/mynewtab1.php?id=__ID__'); // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key. - // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->hasRight('othermodule', 'read'):/mymodule/mynewtab2.php?id=__ID__', + // $this->tabs[] = array('data' => 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->hasRight(\'othermodule\', \'read\'):/mymodule/mynewtab2.php?id=__ID__', // To remove an existing tab identified by code tabname - // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); + // $this->tabs[] = array('data' => 'objecttype:-tabname:NU:conditiontoremove'); // // Where objecttype can be // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) @@ -220,27 +219,27 @@ public function __construct($db) // Dictionaries /* Example: $this->dictionaries=array( - 'langs'=>'mymodule@mymodule', + 'langs' => 'mymodule@mymodule', // List of tables we want to see into dictonnary editor - 'tabname'=>array("table1", "table2", "table3"), + 'tabname' => array("table1", "table2", "table3"), // Label of tables - 'tablib'=>array("Table1", "Table2", "Table3"), + 'tablib' => array("Table1", "Table2", "Table3"), // Request to select fields - 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), + 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Sort order - 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"), + 'tabsqlsort' => array("label ASC", "label ASC", "label ASC"), // List of fields (result of select to show dictionary) - 'tabfield'=>array("code,label", "code,label", "code,label"), + 'tabfield' => array("code,label", "code,label", "code,label"), // List of fields (list of fields to edit a record) - 'tabfieldvalue'=>array("code,label", "code,label", "code,label"), + 'tabfieldvalue' => array("code,label", "code,label", "code,label"), // List of fields (list of fields for insert) - 'tabfieldinsert'=>array("code,label", "code,label", "code,label"), + 'tabfieldinsert' => array("code,label", "code,label", "code,label"), // Name of columns with primary key (try to always name it 'rowid') - 'tabrowid'=>array("rowid", "rowid", "rowid"), + 'tabrowid' => array("rowid", "rowid", "rowid"), // Condition to show each dictionary - 'tabcond'=>array(isModEnabled('mymodule'), isModEnabled('mymodule'), isModEnabled('mymodule')), + 'tabcond' => array(isModEnabled('mymodule'), isModEnabled('mymodule'), isModEnabled('mymodule')), // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY - 'tabhelp'=>array(array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...), + 'tabhelp' => array(array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code' => $langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...), ); */ /* BEGIN MODULEBUILDER DICTIONARIES */ @@ -336,50 +335,50 @@ public function __construct($db) /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */ /* $this->menu[$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'type'=>'left', // This is a Left menu entry - 'titre'=>'MyObject', + 'fk_menu' => 'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type' => 'left', // This is a Left menu entry + 'titre' => 'MyObject', 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth valignmiddle paddingright"'), - 'mainmenu'=>'mymodule', - 'leftmenu'=>'myobject', - 'url'=>'/mymodule/mymoduleindex.php', - 'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>1000+$r, - 'enabled'=>'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. - 'perms'=>'$user->hasRight("mymodule", "myobject", "read")', - 'target'=>'', - 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both - 'object'=>'MyObject' + 'mainmenu' => 'mymodule', + 'leftmenu' => 'myobject', + 'url' => '/mymodule/mymoduleindex.php', + 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position' => 1000 + $r, + 'enabled' => 'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. + 'perms' => '$user->hasRight("mymodule", "myobject", "read")', + 'target' => '', + 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both + 'object' => 'MyObject' ); $this->menu[$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'type'=>'left', // This is a Left menu entry - 'titre'=>'New_MyObject', - 'mainmenu'=>'mymodule', - 'leftmenu'=>'mymodule_myobject_new', - 'url'=>'/mymodule/myobject_card.php?action=create', - 'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>1000+$r, - 'enabled'=>'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'perms'=>'$user->hasRight("mymodule", "myobject", "write")' - 'target'=>'', - 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both - 'object'=>'MyObject' + 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type' => 'left', // This is a Left menu entry + 'titre' => 'New_MyObject', + 'mainmenu' => 'mymodule', + 'leftmenu' => 'mymodule_myobject_new', + 'url' => '/mymodule/myobject_card.php?action=create', + 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position' => 1000 + $r, + 'enabled' => 'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. + 'perms' => '$user->hasRight("mymodule", "myobject", "write")' + 'target' => '', + 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both + 'object' => 'MyObject' ); $this->menu[$r++]=array( - 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'type'=>'left', // This is a Left menu entry - 'titre'=>'List_MyObject', - 'mainmenu'=>'mymodule', - 'leftmenu'=>'mymodule_myobject_list', - 'url'=>'/mymodule/myobject_list.php', - 'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>1000+$r, - 'enabled'=>'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. - 'perms'=>'$user->hasRight("mymodule", "myobject", "read")' - 'target'=>'', - 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both - 'object'=>'MyObject' + 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type' => 'left', // This is a Left menu entry + 'titre' => 'List_MyObject', + 'mainmenu' => 'mymodule', + 'leftmenu' => 'mymodule_myobject_list', + 'url' => '/mymodule/myobject_list.php', + 'langs' => 'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position' => 1000 + $r, + 'enabled' => 'isModEnabled("mymodule")', // Define condition to show or hide menu entry. Use 'isModEnabled("mymodule")' if entry must be visible if module is enabled. + 'perms' => '$user->hasRight("mymodule", "myobject", "read")' + 'target' => '', + 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both + 'object' => 'MyObject' ); */ /* END MODULEBUILDER LEFTMENU MYOBJECT */ @@ -404,10 +403,10 @@ public function __construct($db) include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; //$keyforselect='myobjectline'; $keyforaliasextra='extraline'; $keyforelement='myobjectline@mymodule'; //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; - //$this->export_dependencies_array[$r] = array('myobjectline'=>array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) - //$this->export_special_array[$r] = array('t.field'=>'...'); - //$this->export_examplevalues_array[$r] = array('t.field'=>'Example'); - //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp'); + //$this->export_dependencies_array[$r] = array('myobjectline' => array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) + //$this->export_special_array[$r] = array('t.field' => '...'); + //$this->export_examplevalues_array[$r] = array('t.field' => 'Example'); + //$this->export_help_array[$r] = array('t.field' => 'FieldDescHelp'); $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'mymodule_myobject as t'; //$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'mymodule_myobject_line as tl ON tl.fk_myobject = t.rowid'; diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php index 2f9988bc74191..968920c09fa69 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php @@ -6,7 +6,7 @@ * Copyright (C) 2018-2021 Philippe Grand * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -63,7 +63,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ public function __construct($db) { diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 411a3658018b5..342afa54c7313 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -10,7 +10,7 @@ * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -102,7 +102,7 @@ class pdf_standard_myobject extends ModelePDFMyObject /** * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ public function __construct($db) { @@ -261,6 +261,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede if (getMultidirOutput($object)) { $object->fetch_thirdparty(); + $dir = null; // Definition of $dir and $file if ($object->specimen) { $dir = getMultidirOutput($object); @@ -270,6 +271,9 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede $dir = getMultidirOutput($object)."/".$objectref; $file = $dir."/".$objectref.".pdf"; } + if ($dir === null) { + return 0; + } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); @@ -293,6 +297,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede // Create pdf instance $pdf = pdf_getInstance($this->format); + '@phan-var-force TCPDI|TCPDF $pdf'; $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $pdf->SetAutoPageBreak(1, 0); @@ -346,6 +351,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede $pdf->setSignature($cert, $cert, $this->emetteur->name, '', 2, $info); } + // @phan-suppress-next-line PhanPluginSuspiciousParamOrder $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right @@ -499,7 +505,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede } } - $tab_height = $tab_height - $height_note; + $tab_height -= $height_note; $tab_top = $posyafter + 6; } else { $height_note = 0; @@ -791,7 +797,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede // Pagefoot $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { - $pdf->AliasNbPages(); + $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } $pdf->Close(); @@ -841,15 +847,15 @@ public static function liste_modeles($db, $maxfilenamelength = 0) /** * Show table for lines * - * @param tcpdf $pdf Object PDF - * @param string $tab_top Top position of table - * @param string $tab_height Height of table (rectangle) - * @param int $nexY Y (not used) - * @param Translate $outputlangs Langs object - * @param int<-1,1> $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title - * @param int<0,1> $hidebottom Hide bottom bar of array - * @param string $currency Currency code - * @param ?Translate $outputlangsbis Langs object bis + * @param TCPDF|TCPDI $pdf Object PDF + * @param int $tab_top Top position of table + * @param int $tab_height Height of table (rectangle) + * @param int $nexY Y (not used) + * @param Translate $outputlangs Langs object + * @param int<-1,1> $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title + * @param int<0,1> $hidebottom Hide bottom bar of array + * @param string $currency Currency code + * @param ?Translate $outputlangsbis Langs object bis * @return void */ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null) @@ -880,7 +886,7 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $ //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230'; if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) { - $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR'))); + $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR'))); } } @@ -902,12 +908,12 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $ /** * Show top header of page. * - * @param TCPDF $pdf Object PDF - * @param MyObject $object Object to show - * @param int<0,1> $showaddress 0=no, 1=yes - * @param Translate $outputlangs Object lang for output - * @param ?Translate $outputlangsbis Object lang for output bis - * @return float|int Return topshift value + * @param TCPDF|TCPDI $pdf Object PDF + * @param MyObject $object Object to show + * @param int<0,1> $showaddress 0=no, 1=yes + * @param Translate $outputlangs Object lang for output + * @param ?Translate $outputlangsbis Object lang for output bis + * @return float|int Return topshift value */ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null) { @@ -993,10 +999,12 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output $posy += 1; $pdf->SetFont('', '', $default_font_size - 2); - if ($object->ref_client) { + // @phan-suppress-next-line PhanUndeclaredProperty + if (property_exists($object, 'ref_client') && $object->ref_client) { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); + // @phan-suppress-next-line PhanUndeclaredProperty $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R'); } @@ -1029,7 +1037,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) { $title .= ' - '.$outputlangsbis->transnoentities("Date"); } - $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R'); + $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_creation, "day", false, $outputlangs, true), '', 'R'); if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) { $posy += 3; @@ -1119,6 +1127,8 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output if (is_object($thirdparty)) { $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs); + } else { + $carac_client_name = null; } $mode = 'target'; @@ -1148,6 +1158,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output // Show recipient name $pdf->SetXY($posx + 2, $posy + 3); $pdf->SetFont('', 'B', $default_font_size); + // @phan-suppress-next-line PhanPluginSuspiciousParamOrder $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection); $posy = $pdf->getY(); @@ -1155,6 +1166,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output // Show recipient information $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY($posx + 2, $posy); + // @phan-suppress-next-line PhanPluginSuspiciousParamOrder $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection); } @@ -1166,11 +1178,11 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output /** * Show footer of page. Need this->emetteur object * - * @param TCPDF $pdf PDF - * @param Object $object Object to show - * @param Translate $outputlangs Object lang for output - * @param int<0,1> $hidefreetext 1=Hide free text - * @return int Return height of bottom margin including footer text + * @param TCPDI|TCPDF $pdf PDF + * @param CommonObject $object Object to show + * @param Translate $outputlangs Object lang for output + * @param int<0,1> $hidefreetext 1=Hide free text + * @return int<0,1> Return height of bottom margin including footer text */ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) { @@ -1182,11 +1194,11 @@ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) /** * Define Array Column Field * - * @param CommonObject $object common object - * @param Translate $outputlangs langs + * @param CommonObject $object common object + * @param Translate $outputlangs langs * @param int<0,1> $hidedetails Do not show line details * @param int<0,1> $hidedesc Do not show desc - * @param int<0,1> $hideref Do not show ref + * @param int<0,1> $hideref Do not show ref * @return void */ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) @@ -1242,7 +1254,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide ); // PHOTO - // $rank = $rank + 10; + // $rank += 10; // $this->cols['photo'] = array( // 'rank' => $rank, // 'width' => (!getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH') ? 20 : getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH')), // in mm @@ -1262,7 +1274,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide // } - $rank = $rank + 10; + $rank += 10; $this->cols['vat'] = array( 'rank' => $rank, 'status' => false, @@ -1277,7 +1289,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide $this->cols['vat']['status'] = true; } - $rank = $rank + 10; + $rank += 10; $this->cols['subprice'] = array( 'rank' => $rank, 'width' => 19, // in mm @@ -1288,7 +1300,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide 'border-left' => true, // add left line separator ); - $rank = $rank + 10; + $rank += 10; $this->cols['qty'] = array( 'rank' => $rank, 'width' => 16, // in mm @@ -1299,7 +1311,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide 'border-left' => true, // add left line separator ); - $rank = $rank + 10; + $rank += 10; $this->cols['unit'] = array( 'rank' => $rank, 'width' => 11, // in mm @@ -1313,7 +1325,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide $this->cols['unit']['status'] = true; } - $rank = $rank + 10; + $rank += 10; $this->cols['discount'] = array( 'rank' => $rank, 'width' => 13, // in mm @@ -1327,7 +1339,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide $this->cols['discount']['status'] = true; } - $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100 + $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100 $this->cols['totalexcltax'] = array( 'rank' => $rank, 'width' => 26, // in mm @@ -1356,6 +1368,7 @@ public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hide if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } elseif (empty($reshook)) { + // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys } else { $this->cols = $hookmanager->resArray; diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index d34bee94ea6b6..c8117863f12e4 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -5,7 +5,7 @@ * Copyright (C) 2008i Raphael Bertrand (Resultic) * Copyright (C) 2019-2024 Frédéric France * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -124,8 +124,8 @@ public function getExample() /** * Return next free value * - * @param MyObject $object Object we need next value for - * @return string|int<-1,0> Next free value if OK, <=0 if KO + * @param MyObject $object Object we need next value for + * @return string|int<-1,0> Next value if OK, <=0 if KO */ public function getNextValue($object) { @@ -141,7 +141,7 @@ public function getNextValue($object) return 0; } - $date = $object->date; + $date = $object->date_creation; $numFinal = get_next_value($db, $mask, 'mymodule_myobject', 'ref', '', '', $date); diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php index 3670e7f9c5ea7..bfa3e43c1f68f 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,6 +38,9 @@ class mod_myobject_standard extends ModeleNumRefMyObject */ public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' + /** + * @var string + */ public $prefix = 'MYOBJECT'; /** @@ -118,8 +121,8 @@ public function canBeActivated($object) /** * Return next free value * - * @param MyObject $object Object we need next value for - * @return string|int<-1,0> Next free value if OK, -1 if KO + * @param MyObject $object Object we need next value for + * @return string|int<-1,0> Next value if OK, <=0 if KO */ public function getNextValue($object) { @@ -156,7 +159,7 @@ public function getNextValue($object) if ($max >= (pow(10, 4) - 1)) { $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is } else { - $num = sprintf("%04s", $max + 1); + $num = sprintf("%04u", $max + 1); } dol_syslog("mod_myobject_standard::getNextValue return ".$this->prefix.$yymm."-".$num); diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php b/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php index b32b87c6ab1b7..ea6858106e957 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php @@ -7,7 +7,7 @@ * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2014 Marcos García * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,22 +59,19 @@ public static function liste_modeles($db, $maxfilenamelength = 0) return $list; } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Function to build and write pdf to disk + * Function to build a document on disk * - * @param MyObject $object Source object to generate document from - * @param Translate $outputlangs Lang output object - * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int<0,1> $hidedetails Do not show line details - * @param int<0,1> $hidedesc Do not show desc - * @param int<0,1> $hideref Do not show ref - * @return int<-1,1> 1 if OK, <=0 if KO + * @param MyObject $object Object source to build document + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int<0,1> $hidedetails Do not show line details + * @param int<0,1> $hidedesc Do not show desc + * @param int<0,1> $hideref Do not show ref + * @return int<-1,1> 1 if OK, <=0 if KO */ abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0); - // phpcs:enable } @@ -84,10 +81,17 @@ abstract public function write_file($object, $outputlangs, $srctemplatepath = '' abstract class ModeleNumRefMyObject extends CommonNumRefGenerator { /** - * Return next free value + * Return an example of numbering + * + * @return string Example + */ + abstract public function getExample(); + + /** + * Return next free value * - * @param MyObject $object Object we need next value for - * @return string|int<-1,0> Next free value if OK, -1 if KO + * @param MyObject $object Object we need next value for + * @return string|int<-1,0> Next value if OK, <=0 if KO */ abstract public function getNextValue($object); } diff --git a/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php b/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php index 01ca3c22f643a..47d372c68abc2 100644 --- a/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php +++ b/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php @@ -1,7 +1,7 @@ * Copyright (C) 2024 MDW - * Copyright (C) ---Put your own copyright and developer email here--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ $langs = $GLOBALS['langs']; '@phan-var-force Translate $langs'; $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; -'@phan-var-force MyObject[] $linkedObjectBlock'; +'@phan-var-force array $linkedObjectBlock'; // Load translation files required by the page $langs->load("mymodule"); @@ -51,7 +51,7 @@ trans("MyObject"); ?> getNomUrl(1); ?> - date, 'day'); ?> + date_creation, 'day'); ?> getLibStatut(7); ?> ">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?> diff --git a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php index 18b2f29dfdc0d..89e4ed53480d6 100644 --- a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php +++ b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php @@ -1,7 +1,6 @@ - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -88,7 +87,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf } // Or you can execute some code here - switch ($action) { + switch ($action) { // @phan-suppress-current-line PhanNoopSwitchCases // Users //case 'USER_CREATE': //case 'USER_MODIFY': diff --git a/htdocs/modulebuilder/template/css/mymodule.css.php b/htdocs/modulebuilder/template/css/mymodule.css.php index f243960eceeac..a51d758db5ba5 100644 --- a/htdocs/modulebuilder/template/css/mymodule.css.php +++ b/htdocs/modulebuilder/template/css/mymodule.css.php @@ -1,5 +1,5 @@ 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; diff --git a/htdocs/modulebuilder/template/js/mymodule.js.php b/htdocs/modulebuilder/template/js/mymodule.js.php index 416294e214f63..3620b5ac82850 100644 --- a/htdocs/modulebuilder/template/js/mymodule.js.php +++ b/htdocs/modulebuilder/template/js/mymodule.js.php @@ -1,5 +1,5 @@ 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -96,5 +99,3 @@ ?> /* Javascript library of module MyModule */ - - diff --git a/htdocs/modulebuilder/template/langs/en_US/mymodule.lang b/htdocs/modulebuilder/template/langs/en_US/mymodule.lang index 8677fa5806964..b898de60555fd 100644 --- a/htdocs/modulebuilder/template/langs/en_US/mymodule.lang +++ b/htdocs/modulebuilder/template/langs/en_US/mymodule.lang @@ -1,4 +1,4 @@ -# Copyright (C) ---Put here your own copyright and developer email--- +# Copyright (C) ---Replace with your own copyright and developer email--- # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/htdocs/modulebuilder/template/lib/mymodule.lib.php b/htdocs/modulebuilder/template/lib/mymodule.lib.php index 0ebae6eb74f42..d432a35b4afea 100644 --- a/htdocs/modulebuilder/template/lib/mymodule.lib.php +++ b/htdocs/modulebuilder/template/lib/mymodule.lib.php @@ -1,5 +1,5 @@ */ function mymoduleAdminPrepareHead() { diff --git a/htdocs/modulebuilder/template/lib/mymodule_myobject.lib.php b/htdocs/modulebuilder/template/lib/mymodule_myobject.lib.php index 442908079a5c2..e63dc663ae5d6 100644 --- a/htdocs/modulebuilder/template/lib/mymodule_myobject.lib.php +++ b/htdocs/modulebuilder/template/lib/mymodule_myobject.lib.php @@ -1,5 +1,5 @@ Array of tabs */ function myobjectPrepareHead($object) { diff --git a/htdocs/modulebuilder/template/mymoduleindex.php b/htdocs/modulebuilder/template/mymoduleindex.php index 6405f5c67d935..91781a7d148cd 100644 --- a/htdocs/modulebuilder/template/mymoduleindex.php +++ b/htdocs/modulebuilder/template/mymoduleindex.php @@ -31,7 +31,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -67,7 +70,7 @@ $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5); // Security check - Protection if external user -$socid = GETPOST('socid', 'int'); +$socid = GETPOSTINT('socid'); if (isset($user->socid) && $user->socid > 0) { $action = ''; $socid = $user->socid; diff --git a/htdocs/modulebuilder/template/myobject_agenda.php b/htdocs/modulebuilder/template/myobject_agenda.php index baf04bf9c70fa..b3cbeea107c87 100644 --- a/htdocs/modulebuilder/template/myobject_agenda.php +++ b/htdocs/modulebuilder/template/myobject_agenda.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +48,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -101,10 +104,10 @@ $search_rowid = GETPOST('search_rowid'); $search_agenda_label = GETPOST('search_agenda_label'); -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 @@ -160,7 +163,7 @@ * Actions */ -$parameters = array('id'=>$id); +$parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -266,14 +269,14 @@ $objthirdparty = $object; $objcon = new stdClass(); - $out = '&origin='.urlencode($object->element.(property_exists($object, 'module') ? '@'.$object->module : '')).'&originid='.urlencode($object->id); + $out = '&origin='.urlencode($object->element.(property_exists($object, 'module') ? '@'.$object->module : '')).'&originid='.urlencode((string) $object->id); $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id; $out .= '&backtopage='.urlencode($urlbacktopage); $permok = $user->hasRight('agenda', 'myactions', 'create'); if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) { //$out.=' - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -110,10 +113,12 @@ $extrafields = new ExtraFields($db); $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array($object->element.'card', 'globalcard')); // Note that conf->hooks_modules contains array +$soc = null; // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); + $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Initialize array of search criteria @@ -207,10 +212,10 @@ include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; if ($action == 'set_thirdparty' && $permissiontoadd) { - $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname); + $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname); } if ($action == 'classin' && $permissiontoadd) { - $object->setProject(GETPOST('projectid', 'int')); + $object->setProject(GETPOSTINT('projectid')); } // Actions to send emails @@ -472,7 +477,7 @@ // Show object lines $result = $object->getLinesArray(); - print '
+ print ' @@ -490,7 +495,7 @@ } if (!empty($object->lines)) { - $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1); + $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 1); } // Form to add new line @@ -612,7 +617,7 @@ } // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject')); + $linktoelem = $form->showLinkToObjectBlock($object, array(), array('myobject')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); diff --git a/htdocs/modulebuilder/template/myobject_contact.php b/htdocs/modulebuilder/template/myobject_contact.php index 6f1e63f280b04..7e36ea63d9188 100644 --- a/htdocs/modulebuilder/template/myobject_contact.php +++ b/htdocs/modulebuilder/template/myobject_contact.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -62,10 +65,10 @@ // Load translation files required by the page $langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails")); -$id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility +$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); -$lineid = GETPOST('lineid', 'int'); -$socid = GETPOST('socid', 'int'); +$lineid = GETPOSTINT('lineid'); +$socid = GETPOSTINT('socid'); $action = GETPOST('action', 'aZ09'); // Initialize a technical objects @@ -108,7 +111,7 @@ */ if ($action == 'addcontact' && $permissiontoadd) { - $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); @@ -125,7 +128,7 @@ } } elseif ($action == 'swapstatut' && $permissiontoadd) { // Toggle the status of a contact - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + $result = $object->swapContactStatus(GETPOSTINT('ligne')); } elseif ($action == 'deletecontact' && $permissiontoadd) { // Permission to add on object because this is an update of a link of object, not a deletion of data // Deletes a contact $result = $object->delete_contact($lineid); diff --git a/htdocs/modulebuilder/template/myobject_document.php b/htdocs/modulebuilder/template/myobject_document.php index 85bebb0e65855..3742b25099a04 100644 --- a/htdocs/modulebuilder/template/myobject_document.php +++ b/htdocs/modulebuilder/template/myobject_document.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,7 +50,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -88,13 +91,13 @@ // Get parameters $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm'); -$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); +$id = (GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id')); $ref = GETPOST('ref', 'alpha'); -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 9c63860ff86e5..626cffa950fde 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -91,7 +94,7 @@ // Get parameters $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) -$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? +$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ? $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button $toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list @@ -312,7 +315,7 @@ $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; if ($object->ismultientitymanaged == 1) { - $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOST('search_current_entity', 'int') ? 0 : 1)).")"; + $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")"; } else { $sql .= " WHERE 1 = 1"; } @@ -492,9 +495,9 @@ } } } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) { - $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int')); - $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int')); - $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int')); + $param .= '&search_'.$key.'month='.GETPOSTINT('search_'.$key.'month'); + $param .= '&search_'.$key.'day='.GETPOSTINT('search_'.$key.'day'); + $param .= '&search_'.$key.'year='.GETPOSTINT('search_'.$key.'year'); } elseif ($search[$key] != '') { $param .= '&search_'.$key.'='.urlencode($search[$key]); } @@ -537,8 +540,8 @@ $newcardbutton = ''; -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition')); +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition')); $newcardbutton .= dolGetButtonTitleSeparator(); $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); @@ -553,12 +556,13 @@ if ($search_all) { $setupstring = ''; + // @phan-suppress-next-line PhanEmptyForeach foreach ($fieldstosearchall as $key => $val) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } print ''."\n"; - print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; + print '
'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'
'."\n"; } $moreforfilter = ''; @@ -629,7 +633,7 @@ } elseif ($key == 'lang') { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; $formadmin = new FormAdmin($db); - print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2); + print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2); } else { print ''; } @@ -640,7 +644,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; // Fields from hook -$parameters = array('arrayfields'=>$arrayfields); +$parameters = array('arrayfields' => $arrayfields); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; /*if (!empty($arrayfields['anotherfield']['checked'])) { diff --git a/htdocs/modulebuilder/template/myobject_note.php b/htdocs/modulebuilder/template/myobject_note.php index 283bf743067bb..cecbd7cf14df6 100644 --- a/htdocs/modulebuilder/template/myobject_note.php +++ b/htdocs/modulebuilder/template/myobject_note.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,7 +51,10 @@ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -83,7 +86,7 @@ $langs->loadLangs(array("mymodule@mymodule", "companies")); // Get parameters -$id = GETPOST('id', 'int'); +$id = GETPOSTINT('id'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'aZ09'); diff --git a/htdocs/modulebuilder/template/scripts/mymodule.php b/htdocs/modulebuilder/template/scripts/mymodule.php index 1f59f3a602c17..eb7b634e6dcaa 100644 --- a/htdocs/modulebuilder/template/scripts/mymodule.php +++ b/htdocs/modulebuilder/template/scripts/mymodule.php @@ -1,7 +1,7 @@ #!/usr/bin/env php - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,7 +68,10 @@ // Load Dolibarr environment $res = 0; // Try master.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; @@ -100,7 +103,7 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions -$result = $user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. +$result = $user->fetch(0, 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. if (!($result > 0)) { dol_print_error(null, $user->error); exit; diff --git a/htdocs/modulebuilder/template/sql/data.sql b/htdocs/modulebuilder/template/sql/data.sql index 37860e8bf7b0f..d2bf44a0b2e53 100644 --- a/htdocs/modulebuilder/template/sql/data.sql +++ b/htdocs/modulebuilder/template/sql/data.sql @@ -1,4 +1,4 @@ --- Copyright (C) ---Put here your own copyright and developer email--- +-- Copyright (C) ---Replace with your own copyright and developer email--- -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -29,4 +29,3 @@ --insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MYOBJECT_VALIDATE','MyObject validated','Executed when myobject is validated', 'mymodule', 1000); --insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MYOBJECT_UNVALIDATE','MyObject unvalidated','Executed when myobject is unvalidated', 'mymodule', 1001); --insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MYOBJECT_DELETE','MyObject deleted','Executed when myobject deleted', 'mymodule', 1004); - diff --git a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.key.sql b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.key.sql index fc6b7b0d243ac..a100c64e5bc7b 100644 --- a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.key.sql +++ b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.key.sql @@ -1,4 +1,4 @@ --- Copyright (C) ---Put here your own copyright and developer email--- +-- Copyright (C) ---Replace with your own copyright and developer email--- -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,4 +21,3 @@ ALTER TABLE llx_mymodule_myobject ADD INDEX idx_mymodule_myobject_fieldobject (f --ALTER TABLE llx_mymodule_myobject ADD UNIQUE INDEX uk_mymodule_myobject_fieldxy(fieldx, fieldy); --ALTER TABLE llx_mymodule_myobject ADD CONSTRAINT llx_mymodule_myobject_fk_field FOREIGN KEY (fk_field) REFERENCES llx_mymodule_myotherobject(rowid); - diff --git a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.sql b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.sql index cc9cca0c34a26..84275e204c1ac 100644 --- a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.sql +++ b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject.sql @@ -1,4 +1,4 @@ --- Copyright (C) ---Put here your own copyright and developer email--- +-- Copyright (C) ---Replace with your own copyright and developer email--- -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by diff --git a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql index 462a114674df2..bca79bec4aa87 100644 --- a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql +++ b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql @@ -1,4 +1,4 @@ --- Copyright (C) ---Put here your own copyright and developer email--- +-- Copyright (C) ---Replace with your own copyright and developer email--- -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by diff --git a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.sql b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.sql index e0fc9ff40b97c..53eab2a71794d 100644 --- a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.sql +++ b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.sql @@ -1,4 +1,4 @@ --- Copyright (C) ---Put here your own copyright and developer email--- +-- Copyright (C) ---Replace with your own copyright and developer email--- -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -20,4 +20,3 @@ create table llx_mymodule_myobject_extrafields fk_object integer NOT NULL, import_key varchar(14) -- import key ) ENGINE=innodb; - diff --git a/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php b/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php index 97861ddf147b6..26ccaa84d2827 100644 --- a/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php +++ b/htdocs/modulebuilder/template/test/phpunit/MyObjectTest.php @@ -1,8 +1,7 @@ -/* Copyright (C) 2023 Alexandre Janniaux - * Copyright (C) 2024 MDW - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) 2023 Alexandre Janniaux + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,11 +47,23 @@ * @backupStaticAttributes enabled * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ -class MyObjectTest extends PHPUnit\Framework\TestCase +class MyObjectTest extends PHPUnit\Framework\TestCase // @phan-suppress-current-line PhanUndeclaredExtendedClass { + /** + * @var Conf Saved configuration object + */ protected $savconf; + /** + * @var User Saved User object + */ protected $savuser; + /** + * @var Translate Saved translations object (from $langs) + */ protected $savlangs; + /** + * @var DoliDB Saved database object + */ protected $savdb; /** @@ -63,7 +74,7 @@ class MyObjectTest extends PHPUnit\Framework\TestCase */ public function __construct($name = '') { - parent::__construct($name); + parent::__construct($name); // @phan-suppress-current-line PhanUndeclaredClass //$this->sharedFixture global $conf, $user, $langs, $db; @@ -80,7 +91,7 @@ public function __construct($name = '') /** * Global test setup * - * @return void + * @return void No return value */ public static function setUpBeforeClass(): void { @@ -93,7 +104,7 @@ public static function setUpBeforeClass(): void /** * Unit test setup * - * @return void + * @return void No return value */ protected function setUp(): void { @@ -109,7 +120,7 @@ protected function setUp(): void /** * Unit test teardown * - * @return void + * @return void No return value */ protected function tearDown(): void { @@ -119,7 +130,7 @@ protected function tearDown(): void /** * Global test teardown * - * @return void + * @return void No return value */ public static function tearDownAfterClass(): void { @@ -134,6 +145,7 @@ public static function tearDownAfterClass(): void * A sample test * * @return bool + * @phan-suppress PhanUndeclaredMethod */ public function testSomething() { @@ -145,7 +157,7 @@ public function testSomething() $result = true; - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".((int) $result)."\n"; $this->assertTrue($result); return $result; @@ -155,6 +167,7 @@ public function testSomething() * testMyObjectCreate * * @return int + * @phan-suppress PhanUndeclaredMethod */ public function testMyObjectCreate() { @@ -182,6 +195,7 @@ public function testMyObjectCreate() * * @depends testMyObjectCreate * The depends says test is run only if previous is ok + * @phan-suppress PhanUndeclaredMethod */ public function testMyObjectDelete($id) { @@ -199,4 +213,4 @@ public function testMyObjectDelete($id) $this->assertLessThan($result, 0); return $result; } -} +} // @phan-suppress-current-line PhanUndeclaredClass diff --git a/htdocs/modulebuilder/template/test/phpunit/functional/MyModuleFunctionalTest.php b/htdocs/modulebuilder/template/test/phpunit/functional/MyModuleFunctionalTest.php index 660b4cc4105a5..07de8ce7503b2 100644 --- a/htdocs/modulebuilder/template/test/phpunit/functional/MyModuleFunctionalTest.php +++ b/htdocs/modulebuilder/template/test/phpunit/functional/MyModuleFunctionalTest.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,8 +40,9 @@ * @todo OSX support (Safari, Google Chrome, Mozilla Firefox) * * @package Testmymodule + * @phan-file-suppress PhanPluginUnknownObjectMethodCall,PhanUndeclaredMethod,PhanNonClassMethodCall */ -class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase +class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase // @phan-suppress-current-line PhanUndeclaredExtendedClass { // TODO: move to a global configuration file? /** @var string Base URL of the webserver under test */ @@ -82,15 +83,17 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase /** * Helper function to select links by href * - * @param string $value Href - * @return mixed Helper string + * @param string $value Href + * @return ?string Helper string + * @phan */ protected function byHref($value) { - $anchor = null; $anchors = $this->elements($this->using('tag name')->value('a')); - foreach ($anchors as $anchor) { - if (strstr($anchor->attribute('href'), $value)) { + $anchor = null; + foreach ($anchors as $test_anchor) { + if (\strstr($test_anchor->attribute('href'), $value)) { + $anchor = $test_anchor; break; } } @@ -126,6 +129,7 @@ protected function assertPreConditions() /** * Handle Dolibarr authentication * @return void + * @phan-suppress PhanUndeclaredClassCatch */ private function authenticate() { @@ -174,7 +178,7 @@ public function testModuleEnabled() $this->authenticate(); $module_status_image_path = '//a[contains(@href, "'.self::$module_id.'")]/img'; $module_status_image = $this->byXPath($module_status_image_path); - if (strstr($module_status_image->attribute('src'), 'switch_off.png')) { + if (\strstr($module_status_image->attribute('src'), 'switch_off.png')) { // Enable the module $this->byHref('modMyModule')->click(); } else {