1<?php 2/* Copyright (C) 2010-2011 Regis Houssin <regis.houssin@inodbox.com> 3 * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * \file htdocs/societe/canvas/company/actions_card_company.class.php 21 * \ingroup thirdparty 22 * \brief File of Thirdparty card controller (default canvas) 23 */ 24include_once DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php'; 25 26 27/** 28 * ActionsCardCompany 29 * 30 * Class with controller methods for thirdparty canvas 31 */ 32class ActionsCardCompany extends ActionsCardCommon 33{ 34 /** 35 * Constructor 36 * 37 * @param DoliDB $db Handler acces base de donnees 38 * @param string $dirmodule Name of directory of module 39 * @param string $targetmodule Name of directory of module where canvas is stored 40 * @param string $canvas Name of canvas 41 * @param string $card Name of tab (sub-canvas) 42 */ 43 public function __construct($db, $dirmodule, $targetmodule, $canvas, $card) 44 { 45 $this->db = $db; 46 $this->dirmodule = $dirmodule; 47 $this->targetmodule = $targetmodule; 48 $this->canvas = $canvas; 49 $this->card = $card; 50 } 51 52 /** 53 * Return the title of card 54 * 55 * @param string $action Action code 56 * @return string Title 57 */ 58 private function getTitle($action) 59 { 60 global $langs; 61 62 $out = ''; 63 64 if ($action == 'view') { 65 $out .= $langs->trans("ThirdParty"); 66 } 67 if ($action == 'edit') { 68 $out .= $langs->trans("EditCompany"); 69 } 70 if ($action == 'create') { 71 $out .= $langs->trans("NewCompany"); 72 } 73 74 return $out; 75 } 76 77 78 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 79 /** 80 * Assign custom values for canvas (for example into this->tpl to be used by templates) 81 * 82 * @param string $action Type of action 83 * @param integer $id Id of object 84 * @param string $ref Ref of object 85 * @return void 86 */ 87 public function assign_values(&$action, $id = 0, $ref = '') 88 { 89 // phpcs:enable 90 global $conf, $langs, $user, $mysoc; 91 global $form, $formadmin, $formcompany; 92 93 $ret = $this->getObject($id, $ref); 94 95 parent::assign_values($action); 96 97 $this->tpl['title'] = load_fiche_titre($this->getTitle($action)); 98 99 $this->tpl['profid1'] = $this->object->idprof1; 100 $this->tpl['profid2'] = $this->object->idprof2; 101 $this->tpl['profid3'] = $this->object->idprof3; 102 $this->tpl['profid4'] = $this->object->idprof4; 103 104 if ($conf->use_javascript_ajax && empty($conf->global->MAIN_DISABLEVATCHECK)) { 105 $js = "\n"; 106 $js .= '<script language="JavaScript" type="text/javascript">'; 107 $js .= "function CheckVAT(a) {\n"; 108 $js .= "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,230);\n"; 109 $js .= "}\n"; 110 $js .= '</script>'; 111 $js .= "\n"; 112 $this->tpl['js_checkVatPopup'] = $js; 113 } 114 115 if ($action == 'create' || $action == 'edit') { 116 for ($i = 1; $i <= 4; $i++) { 117 $this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code); 118 $this->tpl['showprofid'.$i] = $formcompany->get_input_id_prof($i, 'idprof'.$i, $this->tpl['profid'.$i], $this->object->country_code); 119 } 120 121 // Type 122 $this->tpl['select_companytype'] = $form->selectarray("typent_id", $formcompany->typent_array(0), $this->object->typent_id); 123 124 // Juridical Status 125 $this->tpl['select_juridicalstatus'] = $formcompany->select_juridicalstatus($this->object->forme_juridique_code, $this->object->country_code); 126 127 // Workforce 128 $this->tpl['select_workforce'] = $form->selectarray("effectif_id", $formcompany->effectif_array(0), $this->object->effectif_id); 129 130 // VAT intra 131 $s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$this->object->tva_intra.'">'; 132 if (empty($conf->global->MAIN_DISABLEVATCHECK)) { 133 $s .= ' '; 134 135 if ($conf->use_javascript_ajax) { 136 $s .= '<a href="#" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>'; 137 $this->tpl['tva_intra'] = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1); 138 } else { 139 $this->tpl['tva_intra'] = $s.'<a href="'.$langs->transcountry("VATIntraCheckURL", $this->object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>'; 140 } 141 } else { 142 $this->tpl['tva_intra'] = $s; 143 } 144 } else { 145 // Confirm delete third party 146 if ($action == 'delete') { 147 $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "1,action-delete"); 148 } 149 150 for ($i = 1; $i <= 4; $i++) { 151 $this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code); 152 $this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i, $this->object); 153 $this->tpl['urlprofid'.$i] = $this->object->id_prof_url($i, $this->object); 154 } 155 156 // TVA intra 157 if ($this->object->tva_intra) { 158 $s = $this->object->tva_intra; 159 $s .= '<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$this->object->tva_intra.'">'; 160 if (empty($conf->global->MAIN_DISABLEVATCHECK)) { 161 $s .= ' '; 162 163 if ($conf->use_javascript_ajax) { 164 $s .= '<a href="#" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>'; 165 $this->tpl['tva_intra'] = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1); 166 } else { 167 $this->tpl['tva_intra'] = $s.'<a href="'.$langs->transcountry("VATIntraCheckURL", $this->object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>'; 168 } 169 } else { 170 $this->tpl['tva_intra'] = $s; 171 } 172 } else { 173 $this->tpl['tva_intra'] = ' '; 174 } 175 176 // Parent company 177 if ($this->object->parent) { 178 $socm = new Societe($this->db); 179 $socm->fetch($this->object->parent); 180 $this->tpl['parent_company'] = $socm->getNomUrl(1).' '.($socm->code_client ? "(".$socm->code_client.")" : ""); 181 $this->tpl['parent_company'] .= ($socm->town ? ' - '.$socm->town : ''); 182 } else { 183 $this->tpl['parent_company'] = $langs->trans("NoParentCompany"); 184 } 185 } 186 } 187 188 /** 189 * Check permissions of a user to show a page and an object. Check read permission 190 * If $_REQUEST['action'] defined, we also check write permission. 191 * 192 * @param User $user User to check 193 * @param string $features Features to check (in most cases, it's module name) 194 * @param int $objectid Object ID if we want to check permission on a particular record (optional) 195 * @param string $dbtablename Table name where object is stored. Not used if objectid is null (optional) 196 * @param string $feature2 Feature to check (second level of permission) 197 * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. (optional) 198 * @param string $dbt_select Field name for select if not rowid. (optional) 199 * @return int 1 200 */ 201 public function restrictedArea($user, $features = 'societe', $objectid = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid') 202 { 203 return restrictedArea($user, $features, $objectid, $dbtablename, $feature2, $dbt_keyfield, $dbt_select); 204 } 205} 206