| Total Complexity | 198 |
| Total Lines | 949 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like FormProjets often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FormProjets, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 41 | class FormProjets extends Form |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * @var DoliDB Database handler. |
||
| 45 | */ |
||
| 46 | public $db; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string Error code (or message) |
||
| 50 | */ |
||
| 51 | public $error = ''; |
||
| 52 | |||
| 53 | public $errors = array(); |
||
| 54 | |||
| 55 | |||
| 56 | public $nboftasks; |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * Constructor |
||
| 61 | * |
||
| 62 | * @param DoliDB $db Database handler |
||
| 63 | */ |
||
| 64 | public function __construct($db) |
||
| 65 | { |
||
| 66 | $this->db = $db; |
||
| 67 | } |
||
| 68 | |||
| 69 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Output a combo list with projects qualified for a third party / user |
||
| 73 | * |
||
| 74 | * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) |
||
| 75 | * @param string|Project $selected Id of preselected project or Project (or ''). Note: If you know the ref, you can also provide it into $selected_input_value to save one request in some cases. |
||
| 76 | * @param string $htmlname Name of HTML field |
||
| 77 | * @param int $maxlength Maximum length of label |
||
| 78 | * @param int $option_only Return only html options lines without the select tag |
||
| 79 | * @param int|string $show_empty Add an empty line |
||
| 80 | * @param int $discard_closed Discard closed projects (0=Keep, 1=hide completely, 2=Disable). Use a negative value to not show the "discarded" tooltip. |
||
| 81 | * @param int $forcefocus Force focus on field (works with javascript only) |
||
| 82 | * @param int $disabled Disabled |
||
| 83 | * @param int $mode 0 for HTML mode and 1 for JSON mode |
||
| 84 | * @param string $filterkey Key to filter on ref or title |
||
| 85 | * @param int $nooutput No print output. Return it only. |
||
| 86 | * @param int $forceaddid Force to add project id in list, event if not qualified |
||
| 87 | * @param string $morecss More css |
||
| 88 | * @param string $htmlid Html id to use instead of htmlname, by example id="htmlid" |
||
| 89 | * @param string $morefilter More filters (Must be a sql sanitized string) |
||
| 90 | * @return string Return html content |
||
| 91 | */ |
||
| 92 | public function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '', $morefilter = '') |
||
| 93 | { |
||
| 94 | // phpcs:enable |
||
| 95 | global $langs, $conf, $form; |
||
| 96 | |||
| 97 | $selected_input_value = ''; |
||
| 98 | if (is_object($selected)) { |
||
| 99 | $selected_input_value = $selected->ref; |
||
| 100 | $selected = $selected->id; |
||
| 101 | } |
||
| 102 | |||
| 103 | $out = ''; |
||
| 104 | |||
| 105 | if (!empty($conf->use_javascript_ajax) && getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) { |
||
| 106 | $placeholder = ''; |
||
| 107 | |||
| 108 | if ($selected && empty($selected_input_value)) { |
||
| 109 | $project = new Project($this->db); |
||
| 110 | $project->fetch($selected); |
||
| 111 | $selected_input_value = $project->ref; |
||
| 112 | } |
||
| 113 | $urloption = 'socid=' . ((int) $socid) . '&htmlname=' . urlencode($htmlname) . '&discardclosed=' . ((int) $discard_closed); |
||
| 114 | if ($morefilter == 'usage_organize_event=1') { |
||
| 115 | $urloption .= '&usage_organize_event=1'; |
||
| 116 | } |
||
| 117 | $out .= '<input type="text" class="minwidth200' . ($morecss ? ' ' . $morecss : '') . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />'; |
||
| 118 | |||
| 119 | $out .= ajax_autocompleter($selected, $htmlname, constant('BASE_URL') . '/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array()); |
||
| 120 | } else { |
||
| 121 | $out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, abs($discard_closed), $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss, $morefilter); |
||
| 122 | } |
||
| 123 | if ($discard_closed > 0) { |
||
| 124 | if (!empty($form)) { |
||
| 125 | $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden")); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | if (empty($nooutput)) { |
||
| 130 | print $out; |
||
| 131 | return ''; |
||
| 132 | } else { |
||
| 133 | return $out; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Returns an array with projects qualified for a third party |
||
| 141 | * |
||
| 142 | * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) |
||
| 143 | * @param int $selected Id project preselected |
||
| 144 | * @param string $htmlname Name of html component |
||
| 145 | * @param int $maxlength Maximum length of label |
||
| 146 | * @param int $option_only Return only html options lines without the select tag |
||
| 147 | * @param int|string $show_empty Add an empty line |
||
| 148 | * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) |
||
| 149 | * @param int $forcefocus Force focus on field (works with javascript only) |
||
| 150 | * @param int $disabled Disabled |
||
| 151 | * @param int $mode 0 for HTML mode and 1 for array return (to be used by json_encode for example) |
||
| 152 | * @param string $filterkey Key to filter on title or ref |
||
| 153 | * @param int $nooutput No print output. Return it only. |
||
| 154 | * @param int $forceaddid Force to add project id in list, event if not qualified |
||
| 155 | * @param string $htmlid Html id to use instead of htmlname |
||
| 156 | * @param string $morecss More CSS |
||
| 157 | * @param string $morefilter More filters (Must be a sql sanitized string) |
||
| 158 | * @return int|string|array HTML string or array of option or <0 if KO |
||
| 159 | */ |
||
| 160 | public function select_projects_list($socid = -1, $selected = 0, $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '', $morecss = 'maxwidth500', $morefilter = '') |
||
| 161 | { |
||
| 162 | // phpcs:enable |
||
| 163 | global $user, $conf, $langs; |
||
| 164 | |||
| 165 | |||
| 166 | if (empty($htmlid)) { |
||
| 167 | $htmlid = $htmlname; |
||
| 168 | } |
||
| 169 | |||
| 170 | $out = ''; |
||
| 171 | $outarray = array(); |
||
| 172 | |||
| 173 | $hideunselectables = false; |
||
| 174 | if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) { |
||
| 175 | $hideunselectables = true; |
||
| 176 | } |
||
| 177 | if (getDolGlobalInt('PROJECT_ALWAYS_DISCARD_CLOSED_PROJECTS_IN_SELECT')) { |
||
| 178 | $discard_closed = 1; |
||
| 179 | } |
||
| 180 | |||
| 181 | $projectsListId = false; |
||
| 182 | if (!$user->hasRight('projet', 'all', 'lire')) { |
||
| 183 | $projectstatic = new Project($this->db); |
||
| 184 | $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1); |
||
| 185 | } |
||
| 186 | |||
| 187 | // Search all projects |
||
| 188 | $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias"; |
||
| 189 | $sql .= " FROM " . $this->db->prefix() . "projet as p LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc"; |
||
| 190 | $sql .= " WHERE p.entity IN (" . getEntity('project') . ")"; |
||
| 191 | if ($projectsListId !== false) { |
||
| 192 | $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")"; |
||
| 193 | } |
||
| 194 | if ($socid == 0) { |
||
| 195 | $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; |
||
| 196 | } |
||
| 197 | if ($socid > 0) { |
||
| 198 | if (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) { |
||
| 199 | $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)"; |
||
| 200 | } elseif (getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') != 'all') { // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma. |
||
| 201 | $sql .= " AND (p.fk_soc IN (" . $this->db->sanitize(((int) $socid) . ", " . getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) . ") OR p.fk_soc IS NULL)"; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | if (!empty($filterkey)) { |
||
| 205 | $sql .= natural_search(array('p.title', 'p.ref'), $filterkey); |
||
| 206 | } |
||
| 207 | if ($morefilter) { |
||
| 208 | $sql .= ' AND (' . $this->db->sanitize($morefilter, 0, 1) . ')'; |
||
| 209 | } |
||
| 210 | $sql .= " ORDER BY p.ref ASC"; |
||
| 211 | |||
| 212 | $resql = $this->db->query($sql); |
||
| 213 | if ($resql) { |
||
| 214 | if (!empty($conf->use_javascript_ajax)) { |
||
| 215 | $morecss .= ' minwidth100'; |
||
| 216 | } |
||
| 217 | if (empty($option_only)) { |
||
| 218 | $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlid . '" name="' . $htmlname . '">'; |
||
| 219 | } |
||
| 220 | if (!empty($show_empty)) { |
||
| 221 | if (is_numeric($show_empty)) { |
||
| 222 | $out .= '<option value="0"> </option>'; |
||
| 223 | } else { |
||
| 224 | $out .= '<option value="-1">' . $show_empty . '</option>'; |
||
| 225 | } |
||
| 226 | } |
||
| 227 | $num = $this->db->num_rows($resql); |
||
| 228 | $i = 0; |
||
| 229 | if ($num) { |
||
| 230 | while ($i < $num) { |
||
| 231 | $obj = $this->db->fetch_object($resql); |
||
| 232 | // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
||
| 233 | if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) { |
||
| 234 | // Do nothing |
||
| 235 | } else { |
||
| 236 | if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected |
||
| 237 | $i++; |
||
| 238 | continue; |
||
| 239 | } |
||
| 240 | |||
| 241 | $labeltoshow = dol_trunc($obj->ref, 18); |
||
| 242 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; |
||
| 243 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
||
| 244 | $labeltoshow .= ', ' . dol_trunc($obj->title, $maxlength); |
||
| 245 | if ($obj->name) { |
||
| 246 | $labeltoshow .= ' - ' . $obj->name; |
||
| 247 | if ($obj->name_alias) { |
||
| 248 | $labeltoshow .= ' (' . $obj->name_alias . ')'; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | $disabled = 0; |
||
| 253 | if ($obj->fk_statut == 0) { |
||
| 254 | $disabled = 1; |
||
| 255 | $labeltoshow .= ' - ' . $langs->trans("Draft"); |
||
| 256 | } elseif ($obj->fk_statut == 2) { |
||
| 257 | if ($discard_closed == 2) { |
||
| 258 | $disabled = 1; |
||
| 259 | } |
||
| 260 | $labeltoshow .= ' - ' . $langs->trans("Closed"); |
||
| 261 | } elseif (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { |
||
| 262 | $disabled = 1; |
||
| 263 | $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany"); |
||
| 264 | } |
||
| 265 | |||
| 266 | if (!empty($selected) && $selected == $obj->rowid) { |
||
| 267 | $out .= '<option value="' . $obj->rowid . '" selected'; |
||
| 268 | //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled |
||
| 269 | $out .= '>' . $labeltoshow . '</option>'; |
||
| 270 | } else { |
||
| 271 | if ($hideunselectables && $disabled && ($selected != $obj->rowid)) { |
||
| 272 | $resultat = ''; |
||
| 273 | } else { |
||
| 274 | $resultat = '<option value="' . $obj->rowid . '"'; |
||
| 275 | if ($disabled) { |
||
| 276 | $resultat .= ' disabled'; |
||
| 277 | } |
||
| 278 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
||
| 279 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
||
| 280 | $resultat .= '>'; |
||
| 281 | $resultat .= $labeltoshow; |
||
| 282 | $resultat .= '</option>'; |
||
| 283 | } |
||
| 284 | $out .= $resultat; |
||
| 285 | |||
| 286 | $outarray[] = array( |
||
| 287 | 'key' => (int) $obj->rowid, |
||
| 288 | 'value' => $obj->ref, |
||
| 289 | 'ref' => $obj->ref, |
||
| 290 | 'labelx' => $labeltoshow, |
||
| 291 | 'label' => ($disabled ? '<span class="opacitymedium">' . $labeltoshow . '</span>' : $labeltoshow), |
||
| 292 | 'disabled' => (bool) $disabled |
||
| 293 | ); |
||
| 294 | } |
||
| 295 | } |
||
| 296 | $i++; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | |||
| 300 | $this->db->free($resql); |
||
| 301 | |||
| 302 | if (!$mode) { |
||
| 303 | if (empty($option_only)) { |
||
| 304 | $out .= '</select>'; |
||
| 305 | } |
||
| 306 | |||
| 307 | // Use select2 selector |
||
| 308 | if (!empty($conf->use_javascript_ajax)) { |
||
| 309 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
||
| 310 | $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus); |
||
| 311 | $out .= $comboenhancement; |
||
| 312 | $morecss .= ' minwidth100'; |
||
| 313 | } |
||
| 314 | |||
| 315 | if (empty($nooutput)) { |
||
| 316 | print $out; |
||
| 317 | return ''; |
||
| 318 | } else { |
||
| 319 | return $out; |
||
| 320 | } |
||
| 321 | } else { |
||
| 322 | return $outarray; |
||
| 323 | } |
||
| 324 | } else { |
||
| 325 | dol_print_error($this->db); |
||
| 326 | return -1; |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Output a combo list with tasks qualified for a third party |
||
| 332 | * |
||
| 333 | * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) |
||
| 334 | * @param int $selected Id task preselected |
||
| 335 | * @param string $htmlname Name of HTML select |
||
| 336 | * @param int $maxlength Maximum length of label |
||
| 337 | * @param int $option_only Return only html options lines without the select tag |
||
| 338 | * @param string $show_empty Add an empty line ('1' or string to show for empty line) |
||
| 339 | * @param int $discard_closed Discard closed projects (0=Keep, 1=hide completely, 2=Disable) |
||
| 340 | * @param int $forcefocus Force focus on field (works with javascript only) |
||
| 341 | * @param int $disabled Disabled |
||
| 342 | * @param string $morecss More css added to the select component |
||
| 343 | * @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids. |
||
| 344 | * @param string $showmore 'all' = Show project info, 'progress' = Show task progression, ''=Show nothing more |
||
| 345 | * @param User $usertofilter User object to use for filtering |
||
| 346 | * @param int $nooutput 1=Return string, do not send to output |
||
| 347 | * |
||
| 348 | * @return int|string Nbr of tasks if OK, <0 if KO. If nooutput=1: Return a HTML select string. |
||
| 349 | */ |
||
| 350 | public function selectTasks($socid = -1, $selected = 0, $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showmore = 'all', $usertofilter = null, $nooutput = 0) |
||
| 351 | { |
||
| 352 | global $user, $conf, $langs; |
||
| 353 | |||
| 354 | |||
| 355 | if (is_null($usertofilter)) { |
||
| 356 | $usertofilter = $user; |
||
| 357 | } |
||
| 358 | |||
| 359 | $out = ''; |
||
| 360 | |||
| 361 | $hideunselectables = false; |
||
| 362 | if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) { |
||
| 363 | $hideunselectables = true; |
||
| 364 | } |
||
| 365 | |||
| 366 | if (empty($projectsListId)) { |
||
| 367 | if (!$usertofilter->hasRight('projet', 'all', 'lire')) { |
||
|
|
|||
| 368 | $projectstatic = new Project($this->db); |
||
| 369 | $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1); |
||
| 370 | } |
||
| 371 | } |
||
| 372 | |||
| 373 | // Search all projects |
||
| 374 | $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,"; |
||
| 375 | $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,"; |
||
| 376 | $sql .= " s.nom as name"; |
||
| 377 | $sql .= " FROM " . $this->db->prefix() . "projet as p"; |
||
| 378 | $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc,"; |
||
| 379 | $sql .= " " . $this->db->prefix() . "projet_task as t"; |
||
| 380 | $sql .= " WHERE p.entity IN (" . getEntity('project') . ")"; |
||
| 381 | $sql .= " AND t.fk_projet = p.rowid"; |
||
| 382 | if ($projectsListId) { |
||
| 383 | $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")"; |
||
| 384 | } |
||
| 385 | if ($socid == 0) { |
||
| 386 | $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; |
||
| 387 | } |
||
| 388 | if ($socid > 0) { |
||
| 389 | $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)"; |
||
| 390 | } |
||
| 391 | $sql .= " ORDER BY p.ref, t.ref ASC"; |
||
| 392 | |||
| 393 | $resql = $this->db->query($sql); |
||
| 394 | if ($resql) { |
||
| 395 | // Use select2 selector |
||
| 396 | if (empty($option_only) && !empty($conf->use_javascript_ajax)) { |
||
| 397 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
||
| 398 | $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); |
||
| 399 | $out .= $comboenhancement; |
||
| 400 | $morecss .= ' minwidth150imp'; |
||
| 401 | } |
||
| 402 | |||
| 403 | if (empty($option_only)) { |
||
| 404 | $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '">'; |
||
| 405 | } |
||
| 406 | if (!empty($show_empty)) { |
||
| 407 | $out .= '<option value="0" class="optiongrey">'; |
||
| 408 | if (!is_numeric($show_empty)) { |
||
| 409 | //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">aaa'; |
||
| 410 | $out .= $show_empty; |
||
| 411 | //if (!empty($conf->use_javascript_ajax)) $out .= '</span>'; |
||
| 412 | } else { |
||
| 413 | $out .= ' '; |
||
| 414 | } |
||
| 415 | $out .= '</option>'; |
||
| 416 | } |
||
| 417 | |||
| 418 | $num = $this->db->num_rows($resql); |
||
| 419 | $i = 0; |
||
| 420 | if ($num) { |
||
| 421 | while ($i < $num) { |
||
| 422 | $obj = $this->db->fetch_object($resql); |
||
| 423 | // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
||
| 424 | if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe', 'lire')) { |
||
| 425 | // Do nothing |
||
| 426 | } else { |
||
| 427 | if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) { |
||
| 428 | $i++; |
||
| 429 | continue; |
||
| 430 | } |
||
| 431 | |||
| 432 | $labeltoshow = ''; |
||
| 433 | $labeltoshowhtml = ''; |
||
| 434 | |||
| 435 | $disabled = 0; |
||
| 436 | if ($obj->fk_statut == Project::STATUS_DRAFT) { |
||
| 437 | $disabled = 1; |
||
| 438 | } elseif ($obj->fk_statut == Project::STATUS_CLOSED) { |
||
| 439 | if ($discard_closed == 2) { |
||
| 440 | $disabled = 1; |
||
| 441 | } |
||
| 442 | } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { |
||
| 443 | $disabled = 1; |
||
| 444 | } |
||
| 445 | |||
| 446 | if (preg_match('/all/', $showmore)) { |
||
| 447 | $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref |
||
| 448 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; |
||
| 449 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
||
| 450 | $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength); |
||
| 451 | $labeltoshowhtml = $labeltoshow; |
||
| 452 | |||
| 453 | if ($obj->name) { |
||
| 454 | $labeltoshow .= ' (' . $obj->name . ')'; |
||
| 455 | $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->name . ')</span>'; |
||
| 456 | } |
||
| 457 | |||
| 458 | $disabled = 0; |
||
| 459 | if ($obj->fk_statut == Project::STATUS_DRAFT) { |
||
| 460 | $disabled = 1; |
||
| 461 | $labeltoshow .= ' - ' . $langs->trans("Draft"); |
||
| 462 | $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Draft") . '</span>'; |
||
| 463 | } elseif ($obj->fk_statut == Project::STATUS_CLOSED) { |
||
| 464 | if ($discard_closed == 2) { |
||
| 465 | $disabled = 1; |
||
| 466 | } |
||
| 467 | $labeltoshow .= ' - ' . $langs->trans("Closed"); |
||
| 468 | $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Closed") . '</span>'; |
||
| 469 | } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { |
||
| 470 | $disabled = 1; |
||
| 471 | $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany"); |
||
| 472 | $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("LinkedToAnotherCompany") . '</span>'; |
||
| 473 | } |
||
| 474 | $labeltoshow .= ' - '; |
||
| 475 | $labeltoshowhtml .= ' - '; |
||
| 476 | } |
||
| 477 | |||
| 478 | // Label for task |
||
| 479 | $labeltoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength); |
||
| 480 | $labeltoshowhtml .= $obj->tref . ' - ' . dol_trunc($obj->tlabel, $maxlength); |
||
| 481 | if ($obj->usage_task && preg_match('/progress/', $showmore)) { |
||
| 482 | $labeltoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>'; |
||
| 483 | $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>'; |
||
| 484 | } |
||
| 485 | |||
| 486 | if (!empty($selected) && $selected == $obj->rowid) { |
||
| 487 | $out .= '<option value="' . $obj->rowid . '" selected'; |
||
| 488 | $out .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"'; |
||
| 489 | //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled |
||
| 490 | $out .= '>' . $labeltoshow . '</option>'; |
||
| 491 | } else { |
||
| 492 | if ($hideunselectables && $disabled && ($selected != $obj->rowid)) { |
||
| 493 | $resultat = ''; |
||
| 494 | } else { |
||
| 495 | $resultat = '<option value="' . $obj->rowid . '"'; |
||
| 496 | if ($disabled) { |
||
| 497 | $resultat .= ' disabled'; |
||
| 498 | } |
||
| 499 | //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; |
||
| 500 | //else $labeltoshow.=' ('.$langs->trans("Private").')'; |
||
| 501 | $resultat .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"'; |
||
| 502 | $resultat .= '>'; |
||
| 503 | $resultat .= $labeltoshow; |
||
| 504 | $resultat .= '</option>'; |
||
| 505 | } |
||
| 506 | $out .= $resultat; |
||
| 507 | } |
||
| 508 | } |
||
| 509 | $i++; |
||
| 510 | } |
||
| 511 | } |
||
| 512 | if (empty($option_only)) { |
||
| 513 | $out .= '</select>'; |
||
| 514 | } |
||
| 515 | |||
| 516 | $this->nboftasks = $num; |
||
| 517 | $this->db->free($resql); |
||
| 518 | |||
| 519 | // Output or return |
||
| 520 | if (empty($nooutput)) { |
||
| 521 | print $out; |
||
| 522 | } else { |
||
| 523 | return $out; |
||
| 524 | } |
||
| 525 | |||
| 526 | return $num; |
||
| 527 | } else { |
||
| 528 | dol_print_error($this->db); |
||
| 529 | return -1; |
||
| 530 | } |
||
| 531 | } |
||
| 532 | |||
| 533 | |||
| 534 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Build a HTML select list of element of same thirdparty to suggest to link them to project |
||
| 538 | * |
||
| 539 | * @param string $table_element Table of the element to update |
||
| 540 | * @param int|string $socid If of thirdparty to use as filter or 'id1,id2,...' |
||
| 541 | * @param string $morecss More CSS |
||
| 542 | * @param int $limitonstatus Add filters to limit length of list to opened status (for example to avoid ERR_RESPONSE_HEADERS_TOO_BIG on project/element.php page). TODO To implement |
||
| 543 | * @param string $projectkey Equivalent key to fk_projet for actual table_element |
||
| 544 | * @param string $placeholder Placeholder |
||
| 545 | * @return int|string The HTML select list of element or '' if nothing or -1 if KO |
||
| 546 | */ |
||
| 547 | public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '') |
||
| 691 | } |
||
| 692 | } |
||
| 693 | |||
| 694 | |||
| 695 | /** |
||
| 696 | * Build a HTML select list of element of same thirdparty to suggest to link them to project |
||
| 697 | * |
||
| 698 | * @param string $htmlname HTML name |
||
| 699 | * @param string $preselected Preselected (int or 'all' or 'none') |
||
| 700 | * @param int $showempty Add an empty line |
||
| 701 | * @param int $useshortlabel Use short label |
||
| 702 | * @param int $showallnone Add choice "All" and "None" |
||
| 703 | * @param int $showpercent Show default probability for status |
||
| 704 | * @param string $morecss Add more css |
||
| 705 | * @param int $noadmininfo 0=Add admin info, 1=Disable admin info |
||
| 706 | * @param int $addcombojs 1=Add a js combo |
||
| 707 | * @return int<-1,-1>|string The HTML select list of element or '' if nothing or -1 if KO |
||
| 708 | */ |
||
| 709 | public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0) |
||
| 710 | { |
||
| 711 | global $conf, $langs, $user; |
||
| 712 | |||
| 713 | $sql = "SELECT rowid, code, label, percent"; |
||
| 714 | $sql .= " FROM " . $this->db->prefix() . 'c_lead_status'; |
||
| 715 | $sql .= " WHERE active = 1"; |
||
| 716 | $sql .= " ORDER BY position"; |
||
| 717 | |||
| 718 | $resql = $this->db->query($sql); |
||
| 719 | if ($resql) { |
||
| 720 | $num = $this->db->num_rows($resql); |
||
| 721 | $i = 0; |
||
| 722 | $sellist = ''; |
||
| 723 | if ($num > 0) { |
||
| 724 | $sellist = '<select class="flat oppstatus' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">'; |
||
| 725 | if ($showempty) { |
||
| 726 | // Without  , strange move of screen when switching value |
||
| 727 | $sellist .= '<option value="-1"> </option>'; |
||
| 728 | } |
||
| 729 | if ($showallnone) { |
||
| 730 | $sellist .= '<option value="all"' . ($preselected == 'all' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OnlyOpportunitiesShort") . '</option>'; |
||
| 731 | $sellist .= '<option value="openedopp"' . ($preselected == 'openedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OpenedOpportunitiesShort") . '</option>'; |
||
| 732 | $sellist .= '<option value="notopenedopp"' . ($preselected == 'notopenedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotOpenedOpportunitiesShort") . '</option>'; |
||
| 733 | $sellist .= '<option value="none"' . ($preselected == 'none' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotAnOpportunityShort") . '</option>'; |
||
| 734 | } |
||
| 735 | while ($i < $num) { |
||
| 736 | $obj = $this->db->fetch_object($resql); |
||
| 737 | |||
| 738 | $sellist .= '<option value="' . $obj->rowid . '" defaultpercent="' . $obj->percent . '" elemcode="' . $obj->code . '"'; |
||
| 739 | if ($obj->rowid == $preselected) { |
||
| 740 | $sellist .= ' selected="selected"'; |
||
| 741 | } |
||
| 742 | $sellist .= '>'; |
||
| 743 | if ($useshortlabel) { |
||
| 744 | $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label); |
||
| 745 | } else { |
||
| 746 | $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label); |
||
| 747 | if ($showpercent) { |
||
| 748 | $finallabel .= ' (' . $obj->percent . '%)'; |
||
| 749 | } |
||
| 750 | } |
||
| 751 | $sellist .= $finallabel; |
||
| 752 | $sellist .= '</option>'; |
||
| 753 | $i++; |
||
| 754 | } |
||
| 755 | $sellist .= '</select>'; |
||
| 756 | |||
| 757 | if ($user->admin && !$noadmininfo) { |
||
| 758 | $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 759 | } |
||
| 760 | |||
| 761 | if ($addcombojs) { |
||
| 762 | $sellist .= ajax_combobox($htmlname); |
||
| 763 | } |
||
| 764 | } |
||
| 765 | /*else |
||
| 766 | { |
||
| 767 | $sellist = '<select class="flat" name="elementselect">'; |
||
| 768 | $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>'; |
||
| 769 | $sellist.= '</select>'; |
||
| 770 | }*/ |
||
| 771 | $this->db->free($resql); |
||
| 772 | |||
| 773 | return $sellist; |
||
| 774 | } else { |
||
| 775 | $this->error = $this->db->lasterror(); |
||
| 776 | $this->errors[] = $this->db->lasterror(); |
||
| 777 | dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR); |
||
| 778 | return -1; |
||
| 779 | } |
||
| 780 | } |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Return combo list of different statuses of orders |
||
| 784 | * |
||
| 785 | * @param string $selected Preselected value |
||
| 786 | * @param int $short Use short labels |
||
| 787 | * @param string $hmlname Name of HTML select element |
||
| 788 | * @return void |
||
| 789 | */ |
||
| 790 | public function selectProjectsStatus($selected = '', $short = 0, $hmlname = 'order_status') |
||
| 791 | { |
||
| 792 | $options = array(); |
||
| 793 | |||
| 794 | // 7 is same label than 6. 8 does not exists (billed is another field) |
||
| 795 | $statustohow = array( |
||
| 796 | '0' => '0', |
||
| 797 | '1' => '1', |
||
| 798 | '2' => '2', |
||
| 799 | ); |
||
| 800 | |||
| 801 | $tmpproject = new Project($this->db); |
||
| 802 | |||
| 803 | foreach ($statustohow as $key => $value) { |
||
| 804 | $tmpproject->statut = $key; |
||
| 805 | $options[$value] = $tmpproject->getLibStatut($short); |
||
| 806 | } |
||
| 807 | |||
| 808 | if (is_array($selected)) { |
||
| 809 | $selectedarray = $selected; |
||
| 810 | } elseif ($selected == 99) { |
||
| 811 | $selectedarray = array(0,1); |
||
| 812 | } else { |
||
| 813 | $selectedarray = explode(',', $selected); |
||
| 814 | } |
||
| 815 | |||
| 816 | print Form::multiselectarray($hmlname, $options, $selectedarray, 0, 0, 'minwidth100'); |
||
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Output a combo list with invoices and lines qualified for a project |
||
| 821 | * |
||
| 822 | * @param int $selectedInvoiceId Id invoice preselected |
||
| 823 | * @param int $selectedLineId Id invoice line preselected |
||
| 824 | * @param string $htmlNameInvoice Name of HTML select for Invoice |
||
| 825 | * @param string $htmlNameInvoiceLine Name of HTML select for Invoice Line |
||
| 826 | * @param string $morecss More css added to the select component |
||
| 827 | * @param array $filters Array of filters |
||
| 828 | * @param int $lineOnly return only option for line |
||
| 829 | * @return string HTML Select |
||
| 830 | */ |
||
| 831 | public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0) |
||
| 942 | } |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Output html select to select opportunity status |
||
| 946 | * |
||
| 947 | * @param string $page Page |
||
| 948 | * @param string $selected Id preselected |
||
| 949 | * @param int $percent_value percentage of the opportunity |
||
| 950 | * @param string $htmlname_status name of HTML element for status select |
||
| 951 | * @param string $htmlname_percent name of HTML element for percent input |
||
| 952 | * @param string $filter optional filters criteras |
||
| 953 | * @param int $nooutput No print output. Return it only. |
||
| 954 | * @return void|string |
||
| 955 | */ |
||
| 956 | public function formOpportunityStatus($page, $selected = '', $percent_value = 0, $htmlname_status = 'none', $htmlname_percent = 'none', $filter = '', $nooutput = 0) |
||
| 990 | } |
||
| 991 | } |
||
| 992 | } |
||
| 993 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.