31 require
'../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
38 $langs->loadLangs(array(
"companies",
"website"));
40 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
41 $show_files =
GETPOST(
'show_files',
'int');
42 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'websitelist';
43 $backtopage =
GETPOST(
'backtopage',
'alpha');
44 $optioncss =
GETPOST(
'optioncss',
'aZ');
49 $socid = $user->socid;
53 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
54 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
55 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
57 if (empty($page) || $page == -1) {
60 $offset = $limit * $page;
61 $pageprev = $page - 1;
62 $pagenext = $page + 1;
64 $sortfield =
't.login';
74 $diroutputmassaction = $conf->website->dir_output.
'/temp/massgeneration/'.$user->id;
75 $hookmanager->initHooks(array(
'websitethirdpartylist'));
78 $extrafields->fetch_name_optionals_label($objectwebsiteaccount->table_element);
80 $search_array_options = $extrafields->getOptionalsFromPost($objectwebsiteaccount->table_element,
'',
'search_');
82 unset($objectwebsiteaccount->fields[
'fk_soc']);
85 $search_all =
GETPOST(
"search_all",
'alpha');
87 foreach ($objectwebsiteaccount->fields as $key => $val) {
88 if (
GETPOST(
'search_'.$key,
'alpha')) {
89 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
94 $fieldstosearchall = array();
95 foreach ($objectwebsiteaccount->fields as $key => $val) {
96 if (!empty($val[
'searchall'])) {
97 $fieldstosearchall[
't.'.$key] = $val[
'label'];
102 $arrayfields = array();
103 foreach ($objectwebsiteaccount->fields as $key => $val) {
105 if (!empty($val[
'visible'])) {
106 $arrayfields[
't.'.$key] = array(
'label'=>$val[
'label'],
'checked'=>(($val[
'visible'] < 0) ? 0 : 1),
'enabled'=>$val[
'enabled']);
111 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_array_fields.tpl.php';
118 $result = $object->fetch($id);
126 $parameters = array(
'id'=>$socid);
127 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
132 if (empty($reshook)) {
134 if (
GETPOST(
'cancel',
'alpha') && !empty($backtopage)) {
135 header(
"Location: ".$backtopage);
140 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
143 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
144 foreach ($objectwebsiteaccount->fields as $key => $val) {
148 $search_array_options = array();
150 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')
151 ||
GETPOST(
'button_search_x',
'alpha') ||
GETPOST(
'button_search.x',
'alpha') ||
GETPOST(
'button_search',
'alpha')) {
156 $objectclass =
'WebsiteAccount';
157 $objectlabel =
'WebsiteAccount';
158 $permissiontoread = $user->rights->societe->lire;
159 $permissiontodelete = $user->rights->societe->supprimer;
160 $uploaddir = $conf->societe->multidir_output[$object->entity];
161 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
170 $contactstatic =
new Contact($db);
174 $langs->load(
"companies");
176 $title = $langs->trans(
"WebsiteAccounts");
180 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
181 $param .=
'&contextpage='.urlencode($contextpage);
184 $param .=
'&id='.urlencode($id);
186 if ($limit > 0 && $limit != $conf->liste_limit) {
187 $param .=
'&limit='.urlencode($limit);
189 foreach ($search as $key => $val) {
190 $param .=
'&search_'.$key.
'='.urlencode($search[$key]);
192 if ($optioncss !=
'') {
193 $param .=
'&optioncss='.urlencode($optioncss);
196 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
200 print
dol_get_fiche_head($head,
'website', $langs->trans(
"ThirdParty"), - 1,
'company');
202 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
204 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
206 print
'<div class="fichecenter">';
208 print
'<div class="underbanner clearboth"></div>';
210 print
'<table class="border centpercent">';
213 if (!empty($conf->global->SOCIETE_USEPREFIX)) {
214 print
'<tr><td class="titlefield">'.$langs->trans(
'Prefix').
'</td><td colspan="3">'.$object->prefix_comm.
'</td></tr>';
217 if ($object->client) {
218 print
'<tr><td class="titlefield">';
219 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
220 print $object->code_client;
221 $tmpcheck = $object->check_codeclient();
222 if ($tmpcheck != 0 && $tmpcheck != -5) {
223 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
228 if ($object->fournisseur) {
229 print
'<tr><td class="titlefield">';
230 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
231 print $object->code_fournisseur;
232 $tmpcheck = $object->check_codefournisseur();
233 if ($tmpcheck != 0 && $tmpcheck != -5) {
234 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
246 if (!empty($conf->website->enabled)) {
247 if (!empty($user->rights->societe->lire)) {
248 $newcardbutton .=
dolGetButtonTitle($langs->trans(
"AddWebsiteAccount"),
'',
'fa fa-plus-circle', DOL_URL_ROOT.
'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id));
250 $newcardbutton .=
dolGetButtonTitle($langs->trans(
"AddAction"),
'',
'fa fa-plus-circle', DOL_URL_ROOT.
'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id),
'', 0);
261 foreach ($objectwebsiteaccount->fields as $key => $val) {
262 $sql .=
"t.".$key.
", ";
265 if (!empty($extrafields->attributes[$object->table_element][
'label'])) {
266 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
267 $sql .= ($extrafields->attributes[$object->table_element][
'type'][$key] !=
'separate' ?
"ef.".$key.
" as options_".$key.
', ' :
'');
271 $parameters = array();
272 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $objectwebsiteaccount);
273 $sql .= $hookmanager->resPrint;
274 $sql = preg_replace(
'/, $/',
'', $sql);
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as t";
276 if (isset($extrafields->attributes[$object->table_element][
'label']) && is_array($extrafields->attributes[$object->table_element][
'label']) && count($extrafields->attributes[$object->table_element][
'label'])) {
277 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as ef on (t.rowid = ef.fk_object)";
279 if ($objectwebsiteaccount->ismultientitymanaged == 1) {
280 $sql .=
" WHERE t.entity IN (".getEntity(
'societeaccount').
")";
282 $sql .=
" WHERE 1 = 1";
284 $sql .=
" AND fk_soc = ".((int) $object->id);
285 foreach ($search as $key => $val) {
286 $mode_search = (($objectwebsiteaccount->isInt($objectwebsiteaccount->fields[$key]) || $objectwebsiteaccount->isFloat($objectwebsiteaccount->fields[$key])) ? 1 : 0);
287 if ($search[$key] !=
'') {
288 $sql .=
natural_search($key, $search[$key], (($key ==
'status') ? 2 : $mode_search));
292 $sql .=
natural_search(array_keys($fieldstosearchall), $search_all);
295 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
297 $parameters = array();
298 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $objectwebsiteaccount);
299 $sql .= $hookmanager->resPrint;
316 $sql .= $db->order($sortfield, $sortorder);
319 $nbtotalofrecords =
'';
320 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
321 $result = $db->query($sql);
322 $nbtotalofrecords = $db->num_rows($result);
323 if (($page * $limit) > $nbtotalofrecords) {
329 $sql .= $db->plimit($limit + 1, $offset);
331 $resql = $db->query($sql);
337 $num = $db->num_rows(
$resql);
339 $arrayofselected = is_array($toselect) ? $toselect : array();
342 $arrayofmassactions = array(
346 if ($user->rights->mymodule->delete) {
347 $arrayofmassactions[
'predelete'] =
'<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans(
"Delete");
349 if (in_array($massaction, array(
'presend',
'predelete'))) {
350 $arrayofmassactions = array();
352 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
354 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
355 if ($optioncss !=
'') {
356 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
358 print
'<input type="hidden" name="token" value="'.newToken().
'">';
359 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
360 print
'<input type="hidden" name="action" value="list">';
361 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
362 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
363 print
'<input type="hidden" name="page" value="'.$page.
'">';
364 print
'<input type="hidden" name="id" value="'.$id.
'">';
365 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
367 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'', 0, $newcardbutton,
'', $limit);
369 $topicmail =
"Information";
370 $modelmail =
"societeaccount";
372 $trackid =
'thi'.$object->id;
373 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
386 $parameters = array();
387 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $objectwebsiteaccount);
388 if (empty($reshook)) {
389 $moreforfilter .= $hookmanager->resPrint;
391 $moreforfilter = $hookmanager->resPrint;
394 if (!empty($moreforfilter)) {
395 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
396 print $moreforfilter;
400 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
401 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
402 $selectedfields .= (count($arrayofmassactions) ?
$form->showCheckAddButtons(
'checkforselect', 1) :
'');
404 print
'<div class="div-table-responsive">';
405 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
410 print
'<tr class="liste_titre">';
411 foreach ($objectwebsiteaccount->fields as $key => $val) {
413 if (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) {
416 if (in_array($val[
'type'], array(
'timestamp'))) {
419 if ($key ==
'status') {
420 $align .= ($align ?
' ' :
'').
'center';
422 if (!empty($arrayfields[
't.'.$key][
'checked'])) {
423 print
'<td class="liste_titre'.($align ?
' '.$align :
'').
'"><input type="text" class="flat maxwidth75" name="search_'.$key.
'" value="'.
dol_escape_htmltag($search[$key]).
'"></td>';
427 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_input.tpl.php';
429 $parameters = array(
'arrayfields'=>$arrayfields);
430 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $objectwebsiteaccount);
431 print $hookmanager->resPrint;
433 print
'<td class="liste_titre maxwidthsearch">';
434 $searchpicto =
$form->showFilterButtons();
442 print
'<tr class="liste_titre">';
443 foreach ($objectwebsiteaccount->fields as $key => $val) {
445 if (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) {
448 if (in_array($val[
'type'], array(
'timestamp'))) {
451 if ($key ==
'status') {
452 $align .= ($align ?
' ' :
'').
'center';
454 if (!empty($arrayfields[
't.'.$key][
'checked'])) {
455 print
getTitleFieldOfList($arrayfields[
't.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'],
't.'.$key,
'', $param, ($align ?
'class="'.$align.
'"' :
''), $sortfield, $sortorder, $align.
' ').
"\n";
460 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_title.tpl.php';
462 $parameters = array(
'arrayfields'=>$arrayfields,
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
463 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $objectwebsiteaccount);
464 print $hookmanager->resPrint;
465 print
getTitleFieldOfList($selectedfields, 0, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'maxwidthsearch center ').
"\n";
470 $needToFetchEachLine = 0;
471 if (isset($extrafields->attributes[$object->table_element][
'computed']) && is_array($extrafields->attributes[$object->table_element][
'computed']) && count($extrafields->attributes[$object->table_element][
'computed']) > 0) {
472 foreach ($extrafields->attributes[$object->table_element][
'computed'] as $key => $val) {
473 if (preg_match(
'/\$object/', $val)) {
474 $needToFetchEachLine++;
482 $totalarray = array();
483 while ($i < min($num, $limit)) {
484 $obj = $db->fetch_object(
$resql);
490 $objectwebsiteaccount->id = $obj->rowid;
491 $objectwebsiteaccount->login = $obj->login;
492 $objectwebsiteaccount->ref = $obj->login;
493 foreach ($objectwebsiteaccount->fields as $key => $val) {
494 if (property_exists($objectwebsiteaccount, $key)) {
495 $objectwebsiteaccount->$key = $obj->$key;
500 print
'<tr class="oddeven">';
501 foreach ($objectwebsiteaccount->fields as $key => $val) {
503 if (in_array($val[
'type'], array(
'date',
'datetime',
'timestamp'))) {
506 if (in_array($val[
'type'], array(
'timestamp'))) {
509 if ($key ==
'status') {
510 $align .= ($align ?
' ' :
'').
'center';
512 if (!empty($arrayfields[
't.'.$key][
'checked'])) {
515 print
' class="'.$align.
'"';
518 if ($key ==
'login') {
519 print $objectwebsiteaccount->getNomUrl(1,
'', 0,
'', 1);
521 print $objectwebsiteaccount->showOutputField($val, $key, $obj->$key,
'');
525 $totalarray[
'nbfield']++;
527 if (!empty($val[
'isameasure']) && $val[
'isameasure'] == 1) {
529 $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.'.$key;
531 if (!isset($totalarray[
'val'])) {
532 $totalarray[
'val'] = array();
534 if (!isset($totalarray[
'val'][
't.'.$key])) {
535 $totalarray[
'val'][
't.'.$key] = 0;
537 $totalarray[
'val'][
't.'.$key] += $objectwebsiteaccount->$key;
542 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_print_fields.tpl.php';
544 $parameters = array(
'arrayfields'=>$arrayfields,
'obj'=>$obj,
'i'=>$i,
'totalarray'=>&$totalarray);
545 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objectwebsiteaccount);
546 print $hookmanager->resPrint;
548 print
'<td class="nowrap center">';
549 if ($massactionbutton || $massaction) {
551 if (in_array($obj->rowid, $arrayofselected)) {
554 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
558 $totalarray[
'nbfield']++;
567 include DOL_DOCUMENT_ROOT.
'/core/tpl/list_print_total.tpl.php';
573 foreach ($arrayfields as $key => $val) {
574 if (!empty($val[
'checked'])) {
578 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';
584 $parameters = array(
'arrayfields'=>$arrayfields,
'sql'=>$sql);
585 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $objectwebsiteaccount);
586 print $hookmanager->resPrint;
588 print
'</table>'.
"\n";
591 print
'</form>'.
"\n";
593 if (in_array(
'builddoc', $arrayofmassactions) && ($nbtotalofrecords ===
'' || $nbtotalofrecords)) {
594 $hidegeneratedfilelistifempty = 1;
595 if ($massaction ==
'builddoc' || $action ==
'remove_file' || $show_files) {
596 $hidegeneratedfilelistifempty = 0;
599 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
603 $urlsource = $_SERVER[
'PHP_SELF'].
'?sortfield='.$sortfield.
'&sortorder='.$sortorder;
604 $urlsource .= str_replace(
'&',
'&', $param);
606 $filedir = $diroutputmassaction;
607 $genallowed = $user->rights->mymodule->read;
608 $delallowed = $user->rights->mymodule->create;
610 print $formfile->showdocuments(
'massfilesarea_mymodule',
'', $filedir, $urlsource, 0, $delallowed,
'', 1, 1, 0, 48, 1, $param, $title,
'',
'',
'',
null, $hidegeneratedfilelistifempty);