/** * Output html form to select a resource * * @param string $selected Preselected type * @param string $htmlname Name of field in form * @param string $filter Optionnal filters criteras (example: 's.rowid <> x') * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param string $filterkey Filter on key value * @param int $outputmode 0=HTML select string, 1=Array, 2=without form tag * @param int $limit Limit number of answers * @return string HTML string with */ function select_resource_list($selected = '', $htmlname = 'fk_resource', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = array(), $filterkey = '', $outputmode = 0, $limit = 20) { global $conf, $user, $langs; $out = ''; $outarray = array(); $resourcestat = new Resource($this->db); $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter = ''); if ($outputmode != 2) { $out = '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; } //$out.= '<input type="hidden" name="action" value="search">'; //$out.= '<input type="hidden" name="id" value="'.$theme->id.'">'; if ($resourcestat) { if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && !$forcecombo) { //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out .= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); } // Construct $out and $outarray $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">' . "\n"; if ($showempty) { $out .= '<option value="-1"></option>' . "\n"; } $num = count($resourcestat->lines); //var_dump($resourcestat->lines); $i = 0; if ($num) { while ($i < $num) { $label = $langs->trans(ucfirst($resourcestat->lines[$i]->element)) . ' : '; $label .= $resourcestat->lines[$i]->ref ? $resourcestat->lines[$i]->ref : '' . $resourcestat->lines[$i]->label; if ($selected > 0 && $selected == $resourcestat->lines[$i]->id) { $out .= '<option value="' . $resourcestat->lines[$i]->id . '" selected="selected">' . $label . '</option>'; } else { $out .= '<option value="' . $resourcestat->lines[$i]->id . '">' . $label . '</option>'; } array_push($outarray, array('key' => $resourcestat->lines[$i]->id, 'value' => $resourcestat->lines[$i]->label, 'label' => $resourcestat->lines[$i]->label)); $i++; if ($i % 10 == 0) { $out .= "\n"; } } } $out .= '</select>' . "\n"; if ($outputmode != 2) { $out .= '<input type="submit" class="button" value="' . $langs->trans("Search") . '"> '; $out .= '</form>'; } } else { dol_print_error($this->db); } if ($outputmode && $outputmode != 2) { return $outarray; } return $out; }
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : ''; // Dot not set 0 here (0 for a date is 1970) } else { $cond_reglement_id = $soc->cond_reglement_id; $mode_reglement_id = $soc->mode_reglement_id; $fk_account = $soc->fk_account; $remise_percent = $soc->remise_percent; $remise_absolue = 0; $dateinvoice = empty($dateinvoice) ? empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : '' : $dateinvoice; // Do not set 0 here (0 for a date is 1970) } $absolute_discount = $soc->getAvailableDiscounts(); if (!empty($conf->use_javascript_ajax)) { require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; print ajax_combobox('fac_replacement'); print ajax_combobox('fac_avoir'); } print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="action" value="add">'; if ($soc->id > 0) { print '<input type="hidden" name="socid" value="' . $soc->id . '">' . "\n"; } print '<input name="facnumber" type="hidden" value="provisoire">'; print '<input name="ref_client" type="hidden" value="' . $ref_client . '">'; print '<input name="ref_int" type="hidden" value="' . $ref_int . '">'; print '<input type="hidden" name="origin" value="' . $origin . '">'; print '<input type="hidden" name="originid" value="' . $originid . '">'; print '<table class="border" width="100%">'; // Ref print '<tr><td class="fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . $langs->trans('Draft') . '</td></tr>';
/** * Output a combo list with projects qualified for a third party * * @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) * @param int $selected Id task preselected * @param string $htmlname Name of HTML select * @param int $maxlength Maximum length of label * @param int $option_only Return only html options lines without the select tag * @param int $show_empty Add an empty line * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) * @param int $forcefocus Force focus on field (works with javascript only) * @param int $disabled Disabled * @return int Nbr of project if OK, <0 if KO */ function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0) { global $user, $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $out = ''; $hideunselectables = false; if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) { $hideunselectables = true; } $projectsListId = false; if (empty($user->rights->projet->all->lire)) { $projectstatic = new Project($this->db); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1); } // Search all projects $sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,'; $sql .= ' s.nom as name'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'projet as p'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON s.rowid = p.fk_soc'; $sql .= ', ' . MAIN_DB_PREFIX . 'projet_task as t'; $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND t.fk_projet = p.rowid"; if ($projectsListId !== false) { $sql .= " AND p.rowid IN (" . $projectsListId . ")"; } if ($socid == 0) { $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; } if ($socid > 0) { $sql .= " AND (p.fk_soc=" . $socid . " OR p.fk_soc IS NULL)"; } $sql .= " ORDER BY p.ref, t.ref ASC"; dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $minmax = ''; // Use select2 selector $nodatarole = ''; if (!empty($conf->use_javascript_ajax)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); $out .= $comboenhancement; $nodatarole = $comboenhancement ? ' data-role="none"' : ''; $minmax = 'minwidth200'; } if (empty($option_only)) { $out .= '<select class="flat' . ($minmax ? ' ' . $minmax : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '"' . $nodatarole . '>'; } if (!empty($show_empty)) { $out .= '<option value="0"> </option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); // 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. if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire) { // Do nothing } else { if ($discard_closed == 1 && $obj->fk_statut == 2) { $i++; continue; } $labeltoshow = dol_trunc($obj->ref, 18); //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; //else $labeltoshow.=' ('.$langs->trans("Private").')'; $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength); if ($obj->name) { $labeltoshow .= ' (' . $obj->name . ')'; } $disabled = 0; if ($obj->fk_statut == 0) { $disabled = 1; $labeltoshow .= ' - ' . $langs->trans("Draft"); } else { if ($obj->fk_statut == 2) { if ($discard_closed == 2) { $disabled = 1; } $labeltoshow .= ' - ' . $langs->trans("Closed"); } else { if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { $disabled = 1; $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany"); } } } // Label for task $labeltoshow .= ' - ' . $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength); if (!empty($selected) && $selected == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '" selected'; //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled $out .= '>' . $labeltoshow . '</option>'; } else { if ($hideunselectables && $disabled && $selected != $obj->rowid) { $resultat = ''; } else { $resultat = '<option value="' . $obj->rowid . '"'; if ($disabled) { $resultat .= ' disabled'; } //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; //else $labeltoshow.=' ('.$langs->trans("Private").')'; $resultat .= '>'; $resultat .= $labeltoshow; $resultat .= '</option>'; } $out .= $resultat; } } $i++; } } if (empty($option_only)) { $out .= '</select>'; } print $out; $this->db->free($resql); return $num; } else { dol_print_error($this->db); return -1; } }
/** * Return list of accounts with label by sub_class of accounts * * @param string $selectid Preselected pcg_type * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options * * @return string String with HTML select */ function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) { global $conf; $out = ''; $sql = "SELECT DISTINCT pcg_subtype "; $sql .= " FROM " . MAIN_DB_PREFIX . "accountingaccount as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_subtype"; dol_syslog(get_class($this) . "::select_pcgsubtype sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $out .= ajax_combobox($htmlname, $event); $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; if ($showempty) { $out .= '<option value="-1"></option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); $label = $obj->pcg_subtype; if ($selectid != '' && $selectid == $obj->pcg_subtype) { $out .= '<option value="' . $obj->pcg_subtype . '" selected>' . $label . '</option>'; } else { $out .= '<option value="' . $obj->pcg_subtype . '">' . $label . '</option>'; } $i++; } } $out .= '</select>'; } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); return -1; } $this->db->free($resql); return $out; }
/** * Return select list for categories (to use in form search selectors) * * @param string $selected Preselected value * @param string $htmlname Name of combo list (example: 'search_sale') * @param User $user Object user * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param int $showempty 1=show also an empty value * @param string $morecss More CSS * @return string Html combo list code */ function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '') { global $conf, $langs; $langs->load('users'); $out = ''; $nodatarole = ''; // Enhance with select2 if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); if ($comboenhancement) { $out .= $comboenhancement; $nodatarole = $comboenhancement ? ' data-role="none"' : ''; } } // Select each sales and print them in a select input $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '"' . $nodatarole . '>'; if ($showempty) { $out .= '<option value="0"> </option>'; } // Get list of users allowed to be viewed $sql_usr = "******"; $sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u"; $sql_usr .= " WHERE u.entity IN (0," . $conf->entity . ")"; if (empty($user->rights->user->user->lire)) { $sql_usr .= " AND u.rowid = " . $user->id; } if (!empty($user->societe_id)) { $sql_usr .= " AND u.fk_soc = " . $user->societe_id; } // Add existing sales representatives of thirdparty of external user if (empty($user->rights->user->user->lire) && $user->societe_id) { $sql_usr .= " UNION "; $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login"; $sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; $sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")"; $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc=" . $user->societe_id; } $sql_usr .= " ORDER BY lastname ASC"; //print $sql_usr;exit; $resql_usr = $this->db->query($sql_usr); if ($resql_usr) { while ($obj_usr = $this->db->fetch_object($resql_usr)) { $out .= '<option value="' . $obj_usr->rowid . '"'; if ($obj_usr->rowid == $selected) { $out .= ' selected'; } $out .= '>'; $out .= dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname); // Complete name with more info $moreinfo = 0; if (!empty($conf->global->MAIN_SHOW_LOGIN)) { $out .= ($moreinfo ? ' - ' : ' (') . $obj_usr->login; $moreinfo++; } if ($showstatus >= 0) { if ($obj_usr->statut == 1 && $showstatus == 1) { $out .= ($moreinfo ? ' - ' : ' (') . $langs->trans('Enabled'); $moreinfo++; } if ($obj_usr->statut == 0) { $out .= ($moreinfo ? ' - ' : ' (') . $langs->trans('Disabled'); $moreinfo++; } } $out .= $moreinfo ? ')' : ''; $out .= '</option>'; } $this->db->free($resql_usr); } else { dol_print_error($this->db); } $out .= '</select>'; return $out; }
/** * Output html form to select a third party * @param selected Preselected type * @param htmlname Name of field in form * @param filter Optionnal filters criteras * @param showempty Add an empty field * @param showtype Show third party type in combolist (customer, prospect or supplier) * @param forcecombo Force to use combo box */ function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0) { global $conf, $user, $langs; $out = ''; // On recherche les societes $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE s.entity = " . $conf->entity; if ($filter) { $sql .= " AND " . $filter; } if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" ORDER BY nom ASC"; dol_syslog("Form::select_societes sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && !$forcecombo) { //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out .= ajax_combobox($htmlname); } $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; if ($showempty) { $out .= '<option value="-1"> </option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); $label = $obj->nom; if ($showtype) { if ($obj->client || $obj->fournisseur) { $label .= ' ('; } if ($obj->client == 1 || $obj->client == 3) { $label .= $langs->trans("Customer"); } if ($obj->client == 2 || $obj->client == 3) { $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect"); } if ($obj->fournisseur) { $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier"); } if ($obj->client || $obj->fournisseur) { $label .= ')'; } } if ($selected > 0 && $selected == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>'; } else { $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>'; } $i++; } } $out .= '</select>'; } else { dol_print_error($this->db); } return $out; }
} else // error { print $elementarray; } print "</table>"; print "<br>\n"; } } // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox('.elementselect'); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); print $comboenhancement; } llxFooter(); $db->close(); /**
/** * Output html form to select a third party * * @param string $selected Preselected type * @param string $htmlname Name of field in form * @param string $filter Optionnal filters criteras * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $event Event options * @return string HTML string with */ function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = array()) { global $conf, $user, $langs; $out = ''; $object = new Societe($this->db); try { $result = $object->getView("list"); } catch (Exception $e) { $this->error = "Fetch : Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n"; dol_print_error($this->db, $this->error); return 0; } // On recherche les societes $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE s.entity IN (" . getEntity('societe', 1) . ")"; if (!empty($user->societe_id)) { $sql .= " AND s.rowid = " . $user->societe_id; } if ($filter) { $sql .= " AND " . $filter; } if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" ORDER BY nom ASC"; dol_syslog(get_class($this) . "::select_company sql=" . $sql); if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && !$forcecombo) { //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out .= ajax_combobox($htmlname, $event); } $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; if ($showempty) { $out .= '<option value="0"></option>'; } if (count($result->rows) > 0) { foreach ($result->rows as $aRow) { $obj = $aRow->value; $label = $obj->ThirdPartyName; if ($showtype) { if ($obj->client || $obj->fournisseur) { $label .= ' ('; } if ($obj->client == 1 || $obj->client == 3) { $label .= $langs->trans("Customer"); } if ($obj->client == 2 || $obj->client == 3) { $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect"); } if ($obj->fournisseur) { $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier"); } if ($obj->client || $obj->fournisseur) { $label .= ')'; } } if ($selected > 0 && $selected == $obj->_id) { $out .= '<option value="' . $obj->_id . '" selected="selected">' . $label . '</option>'; } else { $out .= '<option value="' . $obj->_id . '">' . $label . '</option>'; } $i++; } } $out .= '</select>'; return $out; }
/** * Return select list of groups * * @param string $selected Id group preselected * @param string $htmlname Field name in form * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @param string $exclude Array list of groups id to exclude * @param int $disabled If select list must be disabled * @param string $include Array list of groups id to include * @param int $enableonly Array list of groups id to be enabled. All other must be disabled * @param int $force_entity 0 or Id of environment to force * @return void * @see select_dolusers */ function select_dolgroups($selected = '', $htmlname = 'groupid', $show_empty = 0, $exclude = '', $disabled = 0, $include = '', $enableonly = '', $force_entity = 0) { global $conf, $user, $langs; // Permettre l'exclusion de groupes if (is_array($exclude)) { $excludeGroups = implode("','", $exclude); } // Permettre l'inclusion de groupes if (is_array($include)) { $includeGroups = implode("','", $include); } $out = ''; // On recherche les groupes $sql = "SELECT ug.rowid, ug.nom as name"; if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= ", e.label"; } $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup as ug "; if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=ug.entity"; if ($force_entity) { $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; } else { $sql .= " WHERE ug.entity IS NOT NULL"; } } else { $sql .= " WHERE ug.entity IN (0," . $conf->entity . ")"; } if (is_array($exclude) && $excludeGroups) { $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')"; } if (is_array($include) && $includeGroups) { $sql .= " AND ug.rowid IN ('" . $includeGroups . "')"; } $sql .= " ORDER BY ug.nom ASC"; dol_syslog(get_class($this) . "::select_dolgroups", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; if ($num) { $out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"' . ($disabled ? ' disabled="disabled"' : '') . '>'; if ($show_empty) { $out .= '<option value="-1"' . ($selected == -1 ? ' selected="selected"' : '') . '> </option>' . "\n"; } while ($i < $num) { $obj = $this->db->fetch_object($resql); $disableline = 0; if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) { $disableline = 1; } $out .= '<option value="' . $obj->rowid . '"'; if ($disableline) { $out .= ' disabled="disabled"'; } if (is_object($selected) && $selected->id == $obj->rowid || !is_object($selected) && $selected == $obj->rowid) { $out .= ' selected="selected"'; } $out .= '>'; $out .= $obj->name; if (!empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) { $out .= " (" . $obj->label . ")"; } $out .= '</option>'; $i++; } } else { $out .= '<select class="flat" name="' . $htmlname . '"' . ($show_empty ? '' : ' disabled="disabled"') . '>'; if ($show_empty) { $out .= '<option value="-1"' . ($selected == -1 ? ' selected="selected"' : '') . '></option>' . "\n"; } $out .= '<option value="" disabled="disabled">' . $langs->trans("NoUserGroupDefined") . '</option>'; } $out .= '</select>'; if (!empty($conf->use_javascript_ajax) && !$show_empty) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname); } } else { dol_print_error($this->db); } return $out; }
/** * Return list of auxilary thirdparty accounts * * @param string $selectid Preselected pcg_type * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options * * @return string String with HTML select */ function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) { global $conf; $out = ''; $aux_account = array(); // Auxiliary customer account $sql = "SELECT DISTINCT code_compta, nom "; $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; $sql .= " ORDER BY code_compta"; dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { if (!empty($obj->code_compta)) { $aux_account[$obj->code_compta] = $obj->code_compta . ' (' . $obj->nom . ')'; } } } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); return -1; } $this->db->free($resql); // Auxiliary supplier account $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; $sql .= " ORDER BY code_compta"; dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { if (!empty($obj->code_compta_fournisseur)) { $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur . ' (' . $obj->nom . ')'; } } } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); return -1; } $this->db->free($resql); // Build select if (count($aux_account) > 0) { $out .= ajax_combobox($htmlname, $event); $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; if ($showempty) { $out .= '<option value="-1"></option>'; } foreach ($aux_account as $key => $val) { if ($selectid != '' && $selectid == $key) { $out .= '<option value="' . $key . '" selected>' . $val . '</option>'; } else { $out .= '<option value="' . $key . '">' . $val . '</option>'; } } $out .= '</select>'; } return $out; }
/** * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays * * @param string $selected Preselected code of juridical type * @param int $country_codeid 0=list for all countries, otherwise list only country requested * @param string $filter Add a SQL filter on list * @param string $htmlname HTML name of select * @return string String with HTML select */ function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code') { global $conf, $langs, $user; $langs->load("dict"); $out = ''; // On recherche les formes juridiques actives des pays actifs $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_forme_juridique as f, " . MAIN_DB_PREFIX . "c_country as c"; $sql .= " WHERE f.fk_pays=c.rowid"; $sql .= " AND f.active = 1 AND c.active = 1"; if ($country_codeid) { $sql .= " AND c.code = '" . $country_codeid . "'"; } if ($filter) { $sql .= " " . $filter; } $sql .= " ORDER BY c.code"; dol_syslog(get_class($this) . "::select_juridicalstatus", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $out .= '<div id="particulier2" class="visible">'; $out .= '<select class="flat minwidth200" name="' . $htmlname . '" id="' . $htmlname . '">'; if ($country_codeid) { $out .= '<option value="0"> </option>'; } // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select. $num = $this->db->num_rows($resql); if ($num) { $i = 0; $country = ''; $arraydata = array(); while ($i < $num) { $obj = $this->db->fetch_object($resql); if ($obj->code) { $labelcountry = $langs->trans("Country" . $obj->country_code) != "Country" . $obj->country_code ? $langs->trans("Country" . $obj->country_code) : $obj->country; $labeljs = $langs->trans("JuridicalStatus" . $obj->code) != "JuridicalStatus" . $obj->code ? $langs->trans("JuridicalStatus" . $obj->code) : ($obj->label != '-' ? $obj->label : ''); // $obj->label is already in output charset (converted by database driver) $arraydata[$obj->code] = array('code' => $obj->code, 'label' => $labeljs, 'label_sort' => $labelcountry . '_' . $labeljs, 'country_code' => $obj->country_code, 'country' => $labelcountry); } $i++; } $arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC'); if (empty($country_codeid)) { $arraydata[0] = array('code' => 0, 'label' => '', 'label_sort' => '_', 'country_code' => '', 'country' => ''); } foreach ($arraydata as $key => $val) { if (!$country || $country != $val['country']) { // Show break when we are in multi country mode if (empty($country_codeid) && $val['country_code']) { $out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- ' . $val['country'] . " -----</option>\n"; $country = $val['country']; } } if ($selected > 0 && $selected == $val['code']) { $out .= '<option value="' . $val['code'] . '" selected>'; } else { $out .= '<option value="' . $val['code'] . '">'; } // If translation exists, we use it, otherwise we use default label in database $out .= $val['label']; $out .= '</option>'; } } $out .= '</select>'; if ($user->admin) { $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } // Make select dynamic include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname); $out .= '</div>'; } else { dol_print_error($this->db); } return $out; }
/** * Return list of all contacts (for a third party or all) * * @param int $socid Id ot third party or 0 for all * @param string $selected Id contact pre-selectionne * @param string $htmlname Name of HTML field ('none' for a not editable field) * @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit) * @param string $exclude List of contacts id to exclude * @param string $limitto Disable answers that are not id in this array list * @param string $showfunction Add function into label * @param string $moreclass Add more class to class style * @param bool $options_only Return options only (for ajax treatment) * @param string $showsoc Add company into label * @param int $forcecombo Force to use combo box * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return int <0 if KO, Nb of contact in list if OK */ function selectcontacts($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $options_only = false, $showsoc = 0, $forcecombo = 0, $events = array()) { global $conf, $langs; $langs->load('companies'); $out = ''; // On recherche les societes $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; if ($showsoc > 0) { $sql .= " , s.nom as company"; } $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as sp"; if ($showsoc > 0) { $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc "; } $sql .= " WHERE sp.entity IN (" . getEntity('societe', 1) . ")"; if ($socid > 0) { $sql .= " AND sp.fk_soc=" . $socid; } if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) { $sql .= " AND sp.statut<>0 "; } $sql .= " ORDER BY sp.lastname ASC"; dol_syslog(get_class($this) . "::select_contacts sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($conf->use_javascript_ajax && $conf->global->CONTACT_USE_SEARCH_TO_SELECT && !$forcecombo && !$options_only) { $out .= ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); } if ($htmlname != 'none' || $options_only) { $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">'; } if ($showempty == 1) { $out .= '<option value="0"' . ($selected == '0' ? ' selected="selected"' : '') . '></option>'; } if ($showempty == 2) { $out .= '<option value="0"' . ($selected == '0' ? ' selected="selected"' : '') . '>' . $langs->trans("Internal") . '</option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; $contactstatic = new Contact($this->db); while ($i < $num) { $obj = $this->db->fetch_object($resql); $contactstatic->id = $obj->rowid; $contactstatic->lastname = $obj->lastname; $contactstatic->firstname = $obj->firstname; if ($obj->statut == 1) { if ($htmlname != 'none') { $disabled = 0; if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) { $disabled = 1; } if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) { $disabled = 1; } if ($selected && $selected == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '"'; if ($disabled) { $out .= ' disabled="disabled"'; } $out .= ' selected="selected">'; $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } if ($showsoc > 0 && $obj->company) { $out .= ' - (' . $obj->company . ')'; } $out .= '</option>'; } else { $out .= '<option value="' . $obj->rowid . '"'; if ($disabled) { $out .= ' disabled="disabled"'; } $out .= '>'; $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } if ($showsoc > 0 && $obj->company) { $out .= ' - (' . $obj->company . ')'; } $out .= '</option>'; } } else { if ($selected == $obj->rowid) { $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } if ($showsoc > 0 && $obj->company) { $out .= ' - (' . $obj->company . ')'; } } } } $i++; } } else { $out .= '<option value="-1"' . ($showempty == 2 ? '' : ' selected="selected"') . ' disabled="disabled">' . $langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined") . '</option>'; } if ($htmlname != 'none' || $options_only) { $out .= '</select>'; } $this->num = $num; return $out; } else { dol_print_error($this->db); return -1; } }
function select_contacts_combobox($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $options_only = false, $forcecombo = 0, $event = array()) { global $conf, $langs; $langs->load('companies'); $out = ''; // On recherche les societes $sql = "SELECT sp.rowid, sp.nom as name "; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as sp"; $sql .= " WHERE sp.entity IN (" . getEntity('societe', 1) . ")"; if ($socid > 0) { $sql .= " AND sp.fk_soc=" . $socid; } $sql .= " ORDER BY sp.nom ASC"; dol_syslog(get_class($this) . "::select_contacts_combobox sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($conf->use_javascript_ajax && $conf->global->AGF_CONTACT_USE_SEARCH_TO_SELECT && !$forcecombo) { $out .= ajax_combobox($htmlname, $event); } if ($htmlname != 'none' || $options_only) { $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">'; } if ($showempty) { $out .= '<option value="0"></option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; $contactstatic = new Contact($this->db); while ($i < $num) { $obj = $this->db->fetch_object($resql); $contactstatic->id = $obj->rowid; $contactstatic->name = $obj->name; $contactstatic->lastname = $obj->name; if ($htmlname != 'none') { $disabled = 0; if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) { $disabled = 1; } if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) { $disabled = 1; } if ($selected && $selected == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '"'; if ($disabled) { $out .= ' disabled="disabled"'; } $out .= ' selected="selected">'; $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } $out .= '</option>'; } elseif (!$disabled) { $out .= '<option value="' . $obj->rowid . '"'; if ($disabled) { $out .= ' disabled="disabled"'; } $out .= '>'; $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } $out .= '</option>'; } } else { if ($selected == $obj->rowid) { $out .= $contactstatic->getFullName($langs); if ($showfunction && $obj->poste) { $out .= ' (' . $obj->poste . ')'; } } } $i++; } } else { $out .= '<option value="-1" selected="selected" disabled="disabled">' . $langs->trans("NoContactDefined") . '</option>'; } if ($htmlname != 'none' || $options_only) { $out .= '</select>'; } $this->num = $num; return $out; } else { dol_print_error($this->db); return -1; } }
function select_mandat($selectid, $htmlname = 'mandat', $filter = '', $showempty = 0, $forcecombo = 0, $event = array()) { global $conf, $langs; $sql = "SELECT t.rowid, t.ref_interne"; $sql .= " FROM " . MAIN_DB_PREFIX . "mandat as t"; if (!empty($filter)) { $sql .= ' WHERE ' . $filter; } $sql .= " ORDER BY t.ref_interne"; dol_syslog(get_class($this) . "::select_mandat sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { if ($conf->use_javascript_ajax && !$forcecombo) { $out .= ajax_combobox($htmlname, $event); } $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; if ($showempty) { $out .= '<option value="-1"></option>'; } $num = $this->db->num_rows($result); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($result); $label = stripslashes($obj->ref_interne); if ($selectid > 0 && $selectid == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>'; } else { $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>'; } $i++; } } $out .= '</select>'; $this->db->free($result); return $out; } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_mandat " . $this->error, LOG_ERR); return -1; } }
} } else { $cond_reglement_id = $soc->cond_reglement_id; $mode_reglement_id = $soc->mode_reglement_id; $fk_account = $soc->fk_account; $remise_percent = $soc->remise_percent; $remise_absolue = 0; $dateinvoice = empty($dateinvoice) ? empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : '' : $dateinvoice; // Do not set 0 here (0 for a date is 1970) } $absolute_discount = $soc->getAvailableDiscounts(); if (!empty($conf->use_javascript_ajax)) { require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; print ajax_combobox('fac_replacement'); print ajax_combobox('fac_avoir'); print ajax_combobox('situations'); } print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="action" value="add">'; if ($soc->id > 0) { print '<input type="hidden" name="socid" value="' . $soc->id . '">' . "\n"; } print '<input name="facnumber" type="hidden" value="provisoire">'; print '<input name="ref_client" type="hidden" value="' . $ref_client . '">'; print '<input name="ref_int" type="hidden" value="' . $ref_int . '">'; print '<input type="hidden" name="origin" value="' . $origin . '">'; print '<input type="hidden" name="originid" value="' . $originid . '">'; dol_fiche_head(''); print '<table class="border" width="100%">'; // Ref
/** * Return html select list with available languages (key='en_US', value='United States' for example) * * @param string $selected Langue pre-selectionnee * @param string $htmlname Nom de la zone select * @param int $showauto Affiche choix auto * @param array $filter Array of keys to exclude in list * @param int $showempty Add empty value * @param int $showwarning Show a warning if language is not complete * @param int $disabled Disable edit of select * @param string $morecss Add more css styles * @return string Return HTML select string with list of languages */ function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = 0, $showempty = 0, $showwarning = 0, $disabled = 0, $morecss = '') { global $langs; $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); $out = ''; $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '"' . ($disabled ? ' disabled' : '') . '>'; if ($showempty) { $out .= '<option value=""'; if ($selected == '') { $out .= ' selected'; } $out .= '> </option>'; } if ($showauto) { $out .= '<option value="auto"'; if ($selected == 'auto') { $out .= ' selected'; } $out .= '>' . $langs->trans("AutoDetectLang") . '</option>'; } asort($langs_available); $uncompletelanguages = array('da_DA', 'fi_FI', 'hu_HU', 'is_IS', 'pl_PL', 'ro_RO', 'ru_RU', 'sv_SV', 'tr_TR', 'zh_CN'); foreach ($langs_available as $key => $value) { if ($showwarning && in_array($key, $uncompletelanguages)) { //$value.=' - '.$langs->trans("TranslationUncomplete",$key); } if ($filter && is_array($filter)) { if (!array_key_exists($key, $filter)) { $out .= '<option value="' . $key . '">' . $value . '</option>'; } } else { if ($selected == $key) { $out .= '<option value="' . $key . '" selected>' . $value . '</option>'; } else { $out .= '<option value="' . $key . '">' . $value . '</option>'; } } } $out .= '</select>'; // Make select dynamic include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname); return $out; }
/** * Return HTML string to put an input field into a page * * @param string $key Key of attribute * @param string $value Value to show (for date type it must be in timestamp format) * @param string $moreparam To add more parametes on html input tag * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param int $showsize Value for size attributed * @param int $objectid Current object id * @return string */ function showInputField($key, $value, $moreparam = '', $keyprefix = '', $keysuffix = '', $showsize = 0, $objectid = 0) { global $conf, $langs; $label = $this->attribute_label[$key]; $type = $this->attribute_type[$key]; $size = $this->attribute_size[$key]; $elementtype = $this->attribute_elementtype[$key]; $unique = $this->attribute_unique[$key]; $required = $this->attribute_required[$key]; $param = $this->attribute_param[$key]; $perms = $this->attribute_perms[$key]; $list = $this->attribute_list[$key]; if (empty($showsize)) { if ($type == 'date') { $showsize = 10; } elseif ($type == 'datetime') { $showsize = 19; } elseif (in_array($type, array('int', 'double'))) { $showsize = 10; } else { $showsize = round($size); if ($showsize > 48) { $showsize = 48; } } } if (in_array($type, array('date', 'datetime'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; $showtime = in_array($type, array('datetime')) ? 1 : 0; // Do not show current date when field not required (see select_date() method) if (!$required && $value == '') { $value = '-1'; } require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; global $form; if (!is_object($form)) { $form = new Form($this->db); } // TODO Must also support $moreparam $out = $form->select_date($value, $keysuffix . 'options_' . $key . $keyprefix, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1); } elseif (in_array($type, array('int'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="' . $showsize . '" maxlength="' . $newsize . '" value="' . $value . '"' . ($moreparam ? $moreparam : '') . '>'; } elseif ($type == 'varchar') { $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="' . $showsize . '" maxlength="' . $size . '" value="' . $value . '"' . ($moreparam ? $moreparam : '') . '>'; } elseif ($type == 'text') { require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $doleditor = new DolEditor($keysuffix . 'options_' . $key . $keyprefix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, 5, 100); $out = $doleditor->Create(1); } elseif ($type == 'boolean') { $checked = ''; if (!empty($value)) { $checked = ' checked value="1" '; } else { $checked = ' value="1" '; } $out = '<input type="checkbox" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . '>'; } elseif ($type == 'mail') { $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="32" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '>'; } elseif ($type == 'phone') { $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="20" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '>'; } elseif ($type == 'price') { $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="6" value="' . price($value) . '" ' . ($moreparam ? $moreparam : '') . '> ' . $langs->getCurrencySymbol($conf->currency); } elseif ($type == 'double') { if (!empty($value)) { $value = price($value); } $out = '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="6" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> '; } elseif ($type == 'select') { $out = ''; if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($keysuffix . 'options_' . $key . $keyprefix, array(), 0); } $out .= '<select class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" id="options_' . $key . $keyprefix . '" ' . ($moreparam ? $moreparam : '') . '>'; $out .= '<option value="0"> </option>'; foreach ($param['options'] as $key => $val) { list($val, $parent) = explode('|', $val); $out .= '<option value="' . $key . '"'; $out .= $value == $key ? ' selected' : ''; $out .= !empty($parent) ? ' parent="' . $parent . '"' : ''; $out .= '>' . $val . '</option>'; } $out .= '</select>'; } elseif ($type == 'sellist') { $out = ''; if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out .= ajax_combobox($keysuffix . 'options_' . $key . $keyprefix, array(), 0); } $out .= '<select class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" id="options_' . $key . $keyprefix . '" ' . ($moreparam ? $moreparam : '') . '>'; if (is_array($param['options'])) { $param_list = array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); // 0 : tableName // 1 : label field name // 2 : key fields name (if differ of rowid) // 3 : key field parent (for dependent lists) // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value $keyList = empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'; if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { list($parentName, $parentField) = explode('|', $InfoFieldList[3]); $keyList .= ', ' . $parentField; } if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { if (strpos($InfoFieldList[4], 'extra.') !== false) { $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; } else { $keyList = $InfoFieldList[2] . ' as rowid'; } } $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $keyList .= ', '; $keyList .= implode(', ', $fields_label); } $sqlwhere = ''; $sql = 'SELECT ' . $keyList; $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); } // current object id can be use into filter if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); } else { $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); } //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; } else { $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; } } else { $sqlwhere .= ' WHERE 1'; } // Some tables may have field, some other not. For the moment we disable it. if (in_array($InfoFieldList[0], array('tablewithentity'))) { $sqlwhere .= ' AND entity = ' . $conf->entity; } $sql .= $sqlwhere; //print $sql; $sql .= ' ORDER BY ' . implode(', ', $fields_label); dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $out .= '<option value="0"> </option>'; $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { $labeltoshow = ''; $obj = $this->db->fetch_object($resql); // Several field into label (eq table:code|libelle:rowid) $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $notrans = true; foreach ($fields_label as $field_toshow) { $labeltoshow .= $obj->{$field_toshow} . ' '; } } else { $labeltoshow = $obj->{$InfoFieldList}[1]; } $labeltoshow = dol_trunc($labeltoshow, 45); if ($value == $obj->rowid) { foreach ($fields_label as $field_toshow) { $translabel = $langs->trans($obj->{$field_toshow}); if ($translabel != $obj->{$field_toshow}) { $labeltoshow = dol_trunc($translabel, 18) . ' '; } else { $labeltoshow = dol_trunc($obj->{$field_toshow}, 18) . ' '; } } $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>'; } else { if (!$notrans) { $translabel = $langs->trans($obj->{$InfoFieldList}[1]); if ($translabel != $obj->{$InfoFieldList}[1]) { $labeltoshow = dol_trunc($translabel, 18); } else { $labeltoshow = dol_trunc($obj->{$InfoFieldList}[1], 18); } } if (empty($labeltoshow)) { $labeltoshow = '(not defined)'; } if ($value == $obj->rowid) { $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>'; } if (!empty($InfoFieldList[3])) { $parent = $parentName . ':' . $obj->{$parentField}; } $out .= '<option value="' . $obj->rowid . '"'; $out .= $value == $obj->rowid ? ' selected' : ''; $out .= !empty($parent) ? ' parent="' . $parent . '"' : ''; $out .= '>' . $labeltoshow . '</option>'; } $i++; } $this->db->free($resql); } else { print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; } } $out .= '</select>'; } elseif ($type == 'checkbox') { $out = ''; $value_arr = explode(',', $value); foreach ($param['options'] as $keyopt => $val) { $out .= '<input class="flat" type="checkbox" name="' . $keysuffix . 'options_' . $key . $keyprefix . '[]" ' . ($moreparam ? $moreparam : ''); $out .= ' value="' . $keyopt . '"'; if (is_array($value_arr) && in_array($keyopt, $value_arr)) { $out .= 'checked'; } else { $out .= ''; } $out .= '/>' . $val . '<br>'; } } elseif ($type == 'radio') { $out = ''; foreach ($param['options'] as $keyopt => $val) { $out .= '<input class="flat" type="radio" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" ' . ($moreparam ? $moreparam : ''); $out .= ' value="' . $keyopt . '"'; $out .= $value == $keyopt ? 'checked' : ''; $out .= '/>' . $val . '<br>'; } } elseif ($type == 'chkbxlst') { if (is_array($value)) { $value_arr = $value; } else { $value_arr = explode(',', $value); } if (is_array($param['options'])) { $param_list = array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); // 0 : tableName // 1 : label field name // 2 : key fields name (if differ of rowid) // 3 : key field parent (for dependent lists) // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value $keyList = empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'; if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { list($parentName, $parentField) = explode('|', $InfoFieldList[3]); $keyList .= ', ' . $parentField; } if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { if (strpos($InfoFieldList[4], 'extra.') !== false) { $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; } else { $keyList = $InfoFieldList[2] . ' as rowid'; } } $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $keyList .= ', '; $keyList .= implode(', ', $fields_label); } $sqlwhere = ''; $sql = 'SELECT ' . $keyList; $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); } // current object id can be use into filter if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); } else { $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); } // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; } else { $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; } } else { $sqlwhere .= ' WHERE 1'; } // Some tables may have field, some other not. For the moment we disable it. if (in_array($InfoFieldList[0], array('tablewithentity'))) { $sqlwhere .= ' AND entity = ' . $conf->entity; } // $sql.=preg_replace('/^ AND /','',$sqlwhere); // print $sql; $sql .= $sqlwhere; dol_syslog(get_class($this) . '::showInputField type=chkbxlst', LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { $labeltoshow = ''; $obj = $this->db->fetch_object($resql); // Several field into label (eq table:code|libelle:rowid) $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $notrans = true; foreach ($fields_label as $field_toshow) { $labeltoshow .= $obj->{$field_toshow} . ' '; } } else { $labeltoshow = $obj->{$InfoFieldList}[1]; } $labeltoshow = dol_trunc($labeltoshow, 45); if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { foreach ($fields_label as $field_toshow) { $translabel = $langs->trans($obj->{$field_toshow}); if ($translabel != $obj->{$field_toshow}) { $labeltoshow = dol_trunc($translabel, 18) . ' '; } else { $labeltoshow = dol_trunc($obj->{$field_toshow}, 18) . ' '; } } $out .= '<input class="flat" type="checkbox" name="' . $keysuffix . 'options_' . $key . $keyprefix . '[]" ' . ($moreparam ? $moreparam : ''); $out .= ' value="' . $obj->rowid . '"'; $out .= 'checked'; $out .= '/>' . $labeltoshow . '<br>'; } else { if (!$notrans) { $translabel = $langs->trans($obj->{$InfoFieldList}[1]); if ($translabel != $obj->{$InfoFieldList}[1]) { $labeltoshow = dol_trunc($translabel, 18); } else { $labeltoshow = dol_trunc($obj->{$InfoFieldList}[1], 18); } } if (empty($labeltoshow)) { $labeltoshow = '(not defined)'; } if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { $out .= '<input class="flat" type="checkbox" name="' . $keysuffix . 'options_' . $key . $keyprefix . '[]" ' . ($moreparam ? $moreparam : ''); $out .= ' value="' . $obj->rowid . '"'; $out .= 'checked'; $out .= ''; $out .= '/>' . $labeltoshow . '<br>'; } if (!empty($InfoFieldList[3])) { $parent = $parentName . ':' . $obj->{$parentField}; } $out .= '<input class="flat" type="checkbox" name="' . $keysuffix . 'options_' . $key . $keyprefix . '[]" ' . ($moreparam ? $moreparam : ''); $out .= ' value="' . $obj->rowid . '"'; $out .= is_array($value_arr) && in_array($obj->rowid, $value_arr) ? ' checked ' : ''; $out .= ''; $out .= '/>' . $labeltoshow . '<br>'; } $i++; } $this->db->free($resql); } else { print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; } } $out .= '</select>'; } elseif ($type == 'link') { $out = ''; $param_list = array_keys($param['options']); // 0 : ObjectName // 1 : classPath $InfoFieldList = explode(":", $param_list[0]); dol_include_once($InfoFieldList[1]); if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) { $object = new $InfoFieldList[0]($this->db); $object->fetch($value); $valuetoshow = $object->ref; if ($object->element == 'societe') { $valuetoshow = $object->name; } // Special case for thirdparty because ref is id because name is not unique $out .= '<input type="text" class="flat" name="' . $keysuffix . 'options_' . $key . $keyprefix . '" size="20" value="' . $valuetoshow . '" >'; } else { dol_syslog('Error bad setup of extrafield', LOG_WARNING); $out .= 'Error bad setup of extrafield'; } } /* Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; */ return $out; }
/** * Return list of warehouses * * @param int $selected Id of preselected warehouse ('' for no value, 'ifone'=select value if one value otherwise no value) * @param string $htmlname Name of html select html * @param string $filtertype For filter * @param int $empty 1=Can be empty, 0 if not * @param int $disabled 1=Select is disabled * @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0. * @param string $empty_label Empty label if needed (only if $empty=1) * @param int $showstock 1=show stock count * @param int $forcecombo force combo iso ajax select2 * @param array $events events to add to select2 * @return string HTML select */ function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$empty=0,$disabled=0,$fk_product=0,$empty_label='', $showstock=0, $forcecombo=0, $events=array()) { global $conf,$langs,$user; dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product",LOG_DEBUG); $out=''; $this->loadWarehouses($fk_product); $nbofwarehouses=count($this->cache_warehouses); if ($conf->use_javascript_ajax && ! $forcecombo) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname, $events); $out.= $comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.='<select class="flat"'.($disabled?' disabled':'').' id="'.$htmlname.'" name="'.($htmlname.($disabled?'_disabled':'')).'"'.$nodatarole.'>'; if ($empty) $out.='<option value="-1">'.($empty_label?$empty_label:' ').'</option>'; foreach($this->cache_warehouses as $id => $arraytypes) { $out.='<option value="'.$id.'"'; if ($selected == $id || ($selected == 'ifone' && $nbofwarehouses == 1)) $out.=' selected'; $out.='>'; $out.=$arraytypes['label']; if (($fk_product || ($showstock > 0)) && ($arraytypes['stock'] != 0)) $out.='('.$langs->trans("Stock").':'.$arraytypes['stock'].')'; $out.='</option>'; } $out.='</select>'; if ($disabled) $out.='<input type="hidden" name="'.$htmlname.'" value="'.(($selected>0)?$selected:'').'">'; return $out; }