Skip to content

Commit 17efdc8

Browse files
committed
Clean code
1 parent 5957e79 commit 17efdc8

File tree

1 file changed

+60
-34
lines changed

1 file changed

+60
-34
lines changed

registrationlinks_list.php

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
$id = GETPOST('id', 'int');
7777

7878
// Load variable for pagination
79-
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
79+
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
8080
$sortfield = GETPOST('sortfield', 'aZ09comma');
8181
$sortorder = GETPOST('sortorder', 'aZ09comma');
82-
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
82+
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
8383
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
8484
// If $page is not defined, or '' or -1 or if we click on clear filters
8585
$page = 0;
@@ -118,14 +118,14 @@
118118

119119
// Initialize array of search criterias
120120
$search_all = trim(GETPOST('search_all', 'alphanohtml'));
121-
$search=array();
121+
$search = array();
122122
foreach ($object->fields as $key => $val) {
123123
if (GETPOST('search_'.$key, 'alpha') !== '') {
124124
$search[$key] = GETPOST('search_'.$key, 'alpha');
125125
}
126126
if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
127-
$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
128-
$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
127+
$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
128+
$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
129129
}
130130
}
131131

@@ -146,7 +146,7 @@
146146
$arrayfields['t.'.$key] = array(
147147
'label'=>$val['label'],
148148
'checked'=>(($visible < 0) ? 0 : 1),
149-
'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
149+
'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
150150
'position'=>$val['position'],
151151
'help'=> isset($val['help']) ? $val['help'] : ''
152152
);
@@ -155,6 +155,9 @@
155155
// Extra fields
156156
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
157157

158+
//$arrayfields['t.label']['csslist'] = 'tdoverflowmax100';
159+
//var_dump($arrayfields['t.label']);
160+
158161
$object->fields = dol_sort_array($object->fields, 'position');
159162
$arrayfields = dol_sort_array($arrayfields, 'position');
160163

@@ -175,7 +178,7 @@
175178
$massaction='';
176179
}
177180

178-
$parameters=array();
181+
$parameters=array('arrayfields' => &$arrayfields);
179182
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
180183
if ($reshook < 0) {
181184
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@@ -194,6 +197,7 @@
194197
$search[$key.'_dtend'] = '';
195198
}
196199
}
200+
$search_all = '';
197201
$toselect = array();
198202
$search_array_options=array();
199203
}
@@ -285,7 +289,7 @@
285289
/* If a group by is required
286290
$sql .= " GROUP BY ";
287291
foreach($object->fields as $key => $val) {
288-
$sql .= "t.".$db->escape($key).", ";
292+
$sql .= "t.".$db->sanitize($key).", ";
289293
}
290294
// Add fields from extrafields
291295
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
@@ -335,6 +339,14 @@
335339

336340
$num = $db->num_rows($resql);
337341

342+
// Direct jump if only one record found
343+
if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
344+
$obj = $db->fetch_object($resql);
345+
$id = $obj->rowid;
346+
header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.((int) $id));
347+
exit;
348+
}
349+
338350

339351
// Output page
340352
// --------------------------------------------------------------------
@@ -371,6 +383,9 @@ function init_myfunc()
371383
if ($optioncss != '') {
372384
$param .= '&optioncss='.urlencode($optioncss);
373385
}
386+
if ($groupby != '') {
387+
$param .= '&groupby='.urlencode($groupby);
388+
}
374389
foreach ($search as $key => $val) {
375390
if (is_array($search[$key])) {
376391
foreach ($search[$key] as $skey) {
@@ -379,17 +394,17 @@ function init_myfunc()
379394
}
380395
}
381396
} elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
382-
$param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
383-
$param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
384-
$param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
397+
$param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
398+
$param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
399+
$param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
385400
} elseif ($search[$key] != '') {
386401
$param .= '&search_'.$key.'='.urlencode($search[$key]);
387402
}
388403
}
389404
// Add $param from extra fields
390405
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
391406
// Add $param from hooks
392-
$parameters = array();
407+
$parameters = array('param' => &$param);
393408
$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
394409
$param .= $hookmanager->resPrint;
395410

@@ -430,9 +445,11 @@ function init_myfunc()
430445

431446
print '<span class="opacitymedium">'.$langs->trans("RegistrationURLDesc").'</span><br><br>';
432447

433-
if ($sall) {
448+
if ($search_all) {
449+
$setupstring = '';
434450
foreach ($fieldstosearchall as $key => $val) {
435451
$fieldstosearchall[$key]=$langs->trans($val);
452+
$setupstring .= $key."=".$val.";";
436453
}
437454
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'</div>';
438455
}
@@ -453,9 +470,6 @@ function init_myfunc()
453470
if (! empty($moreforfilter)) {
454471
print '<div class="liste_titre liste_titre_bydiv centpercent">';
455472
print $moreforfilter;
456-
$parameters = array();
457-
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
458-
print $hookmanager->resPrint;
459473
print '</div>';
460474
}
461475

@@ -464,7 +478,7 @@ function init_myfunc()
464478
$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
465479
$selectedfields.=(count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
466480

467-
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
481+
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
468482
print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
469483

470484

@@ -479,7 +493,7 @@ function init_myfunc()
479493
print '</td>';
480494
}
481495
foreach ($object->fields as $key => $val) {
482-
$searchkey = empty($search[$key]) ? '' : $search[$key];
496+
//$searchkey = empty($search[$key]) ? '' : $search[$key];
483497
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
484498
if ($key == 'status') {
485499
$cssforfield .= ($cssforfield ? ' ' : '').'center';
@@ -493,7 +507,7 @@ function init_myfunc()
493507
if (!empty($arrayfields['t.'.$key]['checked'])) {
494508
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
495509
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
496-
print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
510+
print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
497511
} elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
498512
print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
499513
} elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
@@ -506,9 +520,9 @@ function init_myfunc()
506520
} elseif ($key == 'lang') {
507521
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
508522
$formadmin = new FormAdmin($db);
509-
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
523+
print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
510524
} else {
511-
print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
525+
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
512526
}
513527
print '</td>';
514528
}
@@ -518,7 +532,7 @@ function init_myfunc()
518532

519533
// Fields from hook
520534
$parameters=array('arrayfields'=>$arrayfields);
521-
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
535+
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
522536
print $hookmanager->resPrint;
523537
// Link
524538
print '<td class="liste_titre">';
@@ -578,8 +592,8 @@ function init_myfunc()
578592
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
579593
print $hookmanager->resPrint;
580594
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
581-
print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
582-
$totalarray['nbfield']++; // For the column action
595+
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
596+
$totalarray['nbfield']++;
583597
}
584598
print '</tr>'."\n";
585599

@@ -588,7 +602,7 @@ function init_myfunc()
588602
$needToFetchEachLine=0;
589603
if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
590604
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
591-
if (preg_match('/\$object/', $val)) {
605+
if (!is_null($val) && preg_match('/\$object/', $val)) {
592606
$needToFetchEachLine++; // There is at least one compute field that use $object
593607
}
594608
}
@@ -610,17 +624,26 @@ function init_myfunc()
610624

611625
// Store properties in $object
612626
$object->setVarsFromFetchObj($obj);
627+
$object->type = Product::TYPE_SERVICE;
613628
$object->status = $obj->status;
614629
$object->status_buy = $obj->status_buy;
615630
$object->status_batch = $obj->status_batch;
616631

617632
if ($mode == 'kanban') {
618633
if ($i == 0) {
619-
print '<tr><td colspan="'.$savnbfield.'">';
620-
print '<div class="box-flex-container">';
634+
print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
635+
print '<div class="box-flex-container kanban">';
621636
}
622637
// Output Kanban
623-
print $object->getKanbanView('');
638+
$selected = -1;
639+
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
640+
$selected = 0;
641+
if (in_array($object->id, $arrayofselected)) {
642+
$selected = 1;
643+
}
644+
}
645+
//print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
646+
print $object->getKanbanView('', array('selected' => $selected));
624647
if ($i == ($imaxinloop - 1)) {
625648
print '</div>';
626649
print '</td></tr>';
@@ -644,6 +667,8 @@ function init_myfunc()
644667
$totalarray['nbfield']++;
645668
}
646669
}
670+
671+
// Fields
647672
foreach ($object->fields as $key => $val) {
648673
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
649674
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
@@ -653,18 +678,18 @@ function init_myfunc()
653678
}
654679

655680
if (in_array($val['type'], array('timestamp'))) {
656-
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
681+
$cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
657682
} elseif ($key == 'ref') {
658-
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
683+
$cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
659684
}
660685

661-
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
686+
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
662687
$cssforfield .= ($cssforfield ? ' ' : '').'right';
663688
}
664689

665690
if (!empty($arrayfields['t.'.$key]['checked'])) {
666-
print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
667-
if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
691+
print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
692+
if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
668693
print ' title="'.dol_escape_htmltag($object->$key).'"';
669694
}
670695
print '>';
@@ -697,6 +722,7 @@ function init_myfunc()
697722
}
698723
// Extra fields
699724
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
725+
700726
// Link
701727
print '<td class="nowrap">';
702728
$helponurl=$langs->trans('ShowMoreParametersForRegisterUrls');
@@ -761,7 +787,7 @@ function init_myfunc()
761787

762788
print '</form>'."\n";
763789

764-
if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
790+
if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
765791
$hidegeneratedfilelistifempty=1;
766792
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
767793
$hidegeneratedfilelistifempty = 0;

0 commit comments

Comments
 (0)