PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/adherents/canvas/actions_adherentcard_common.class.php

http://github.com/Dolibarr/dolibarr
PHP | 288 lines | 166 code | 45 blank | 77 comment | 53 complexity | 42910a1725db89187a98ee82704a6279 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2012 Philippe Grand <philippe.grand@atoo-net.com>
  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. * \file htdocs/adherents/canvas/actions_adherentcard_common.class.php
  20. * \ingroup adherent
  21. * \brief File of class Thirdparty member card controller (common)
  22. */
  23. /**
  24. * Class to manage members using default canvas
  25. */
  26. abstract class ActionsAdherentCardCommon
  27. {
  28. /**
  29. * @var DoliDB Database handler.
  30. */
  31. public $db;
  32. public $dirmodule;
  33. public $targetmodule;
  34. public $canvas;
  35. public $card;
  36. //! Template container
  37. public $tpl = array();
  38. //! Object container
  39. public $object;
  40. /**
  41. * @var string Error code (or message)
  42. */
  43. public $error = '';
  44. /**
  45. * @var string[] Error codes (or messages)
  46. */
  47. public $errors = array();
  48. /**
  49. * Get object
  50. *
  51. * @param int $id Object id
  52. * @return object Object loaded
  53. */
  54. public function getObject($id)
  55. {
  56. //$ret = $this->getInstanceDao();
  57. /*if (is_object($this->object) && method_exists($this->object,'fetch'))
  58. {
  59. if (! empty($id)) $this->object->fetch($id);
  60. }
  61. else
  62. {*/
  63. $object = new Adherent($this->db);
  64. if (!empty($id)) {
  65. $object->fetch($id);
  66. }
  67. $this->object = $object;
  68. //}
  69. }
  70. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  71. /**
  72. * Set content of ->tpl array, to use into template
  73. *
  74. * @param string $action Type of action
  75. * @param int $id Id
  76. * @return string HTML output
  77. */
  78. public function assign_values(&$action, $id)
  79. {
  80. // phpcs:enable
  81. global $conf, $langs, $user, $canvas;
  82. global $form, $formcompany, $objsoc;
  83. if ($action == 'add' || $action == 'update') {
  84. $this->assign_post();
  85. }
  86. foreach ($this->object as $key => $value) {
  87. $this->tpl[$key] = $value;
  88. }
  89. $this->tpl['error'] = $this->error;
  90. $this->tpl['errors'] = $this->errors;
  91. if ($action == 'create' || $action == 'edit') {
  92. if ($conf->use_javascript_ajax) {
  93. $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
  94. jQuery(document).ready(function () {
  95. jQuery("#selectcountry_id").change(function() {
  96. document.formsoc.action.value="'.$action.'";
  97. document.formsoc.canvas.value="'.$canvas.'";
  98. document.formsoc.submit();
  99. });
  100. })
  101. </script>'."\n";
  102. }
  103. if (is_object($objsoc) && $objsoc->id > 0) {
  104. $this->tpl['company'] = $objsoc->getNomUrl(1);
  105. $this->tpl['company_id'] = $objsoc->id;
  106. } else {
  107. $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1);
  108. }
  109. // Civility
  110. $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id);
  111. // Predefined with third party
  112. if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE')) {
  113. if (dol_strlen(trim($this->object->address)) == 0) {
  114. $this->tpl['address'] = $objsoc->address;
  115. }
  116. if (dol_strlen(trim($this->object->zip)) == 0) {
  117. $this->object->zip = $objsoc->zip;
  118. }
  119. if (dol_strlen(trim($this->object->town)) == 0) {
  120. $this->object->town = $objsoc->town;
  121. }
  122. if (dol_strlen(trim($this->object->phone_perso)) == 0) {
  123. $this->object->phone_perso = $objsoc->phone;
  124. }
  125. if (dol_strlen(trim($this->object->phone_mobile)) == 0) {
  126. $this->object->phone_mobile = $objsoc->phone_mobile;
  127. }
  128. if (dol_strlen(trim($this->object->email)) == 0) {
  129. $this->object->email = $objsoc->email;
  130. }
  131. }
  132. // Zip
  133. $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
  134. // Town
  135. $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  136. if (dol_strlen(trim($this->object->country_id)) == 0) {
  137. $this->object->country_id = $objsoc->country_id;
  138. }
  139. // Country
  140. $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
  141. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  142. if ($user->admin) {
  143. $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  144. }
  145. // State
  146. if ($this->object->country_id) {
  147. $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
  148. } else {
  149. $this->tpl['select_state'] = $countrynotdefined;
  150. }
  151. // Physical or Moral
  152. $selectarray = array('0'=>$langs->trans("Physical"), '1'=>$langs->trans("Moral"));
  153. $this->tpl['select_morphy'] = $form->selectarray('morphy', $selectarray, $this->object->morphy, 0);
  154. }
  155. if ($action == 'view' || $action == 'edit' || $action == 'delete') {
  156. // Emailing
  157. if (!empty($conf->mailing->enabled)) {
  158. $langs->load("mails");
  159. $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings();
  160. }
  161. // Dolibarr user
  162. if ($this->object->user_id) {
  163. $dolibarr_user = new User($this->db);
  164. $result = $dolibarr_user->fetch($this->object->user_id);
  165. $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1);
  166. } else {
  167. $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
  168. }
  169. }
  170. if ($action == 'view' || $action == 'delete') {
  171. $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id');
  172. if ($this->object->socid > 0) {
  173. $objsoc = new Societe($this->db);
  174. $objsoc->fetch($this->object->socid);
  175. $this->tpl['company'] = $objsoc->getNomUrl(1);
  176. } else {
  177. $this->tpl['company'] = $langs->trans("AdherentNotLinkedToThirdParty");
  178. }
  179. $this->tpl['civility'] = $this->object->getCivilityLabel();
  180. $this->tpl['address'] = dol_nl2br($this->object->address);
  181. $this->tpl['zip'] = ($this->object->zip ? $this->object->zip.'&nbsp;' : '');
  182. $img = picto_from_langcode($this->object->country_code);
  183. $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
  184. $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
  185. $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
  186. $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
  187. $this->tpl['visibility'] = $this->object->getmorphylib($this->object->morphy);
  188. $this->tpl['note'] = nl2br($this->object->note);
  189. }
  190. if ($action == 'create_user') {
  191. // Full firstname and lastname separated with a dot : firstname.lastname
  192. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  193. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  194. $login = dol_buildlogin($this->object->lastname, $this->object->firstname);
  195. $generated_password = getRandomPassword(false);
  196. $password = $generated_password;
  197. // Create a form array
  198. $formquestion = array(
  199. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
  200. array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
  201. $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id, $langs->trans("CreateDolibarrLogin"), $langs->trans("ConfirmCreateAdherent"), "confirm_create_user", $formquestion, 'no');
  202. }
  203. }
  204. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  205. /**
  206. * Assign POST values into object
  207. *
  208. * @return string HTML output
  209. */
  210. private function assign_post()
  211. {
  212. // phpcs:enable
  213. global $langs, $mysoc;
  214. $this->object->old_name = GETPOST("old_name");
  215. $this->object->old_firstname = GETPOST("old_firstname");
  216. $this->object->fk_soc = GETPOST("fk_soc");
  217. $this->object->lastname = GETPOST("lastname");
  218. $this->object->firstname = GETPOST("firstname");
  219. $this->object->civility_id = GETPOST("civility_id");
  220. $this->object->address = GETPOST("address");
  221. $this->object->zip = GETPOST("zipcode");
  222. $this->object->town = GETPOST("town");
  223. $this->object->country_id = GETPOST("country_id", 'int') ? GETPOST("country_id", 'int') : $mysoc->country_id;
  224. $this->object->state_id = GETPOST("state_id", 'int');
  225. $this->object->phone_perso = GETPOST("phone_perso");
  226. $this->object->phone_mobile = GETPOST("phone_mobile");
  227. $this->object->email = GETPOST("email", 'alphawithlgt');
  228. $this->object->note = GETPOST("note", 'restricthtml');
  229. $this->object->canvas = GETPOST("canvas");
  230. // We set country_id, and country_code label of the chosen country
  231. if ($this->object->country_id) {
  232. $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_country WHERE rowid = ".((int) $this->object->country_id);
  233. $resql = $this->db->query($sql);
  234. if ($resql) {
  235. $obj = $this->db->fetch_object($resql);
  236. $this->object->country_code = $obj->code;
  237. $this->object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->libelle;
  238. } else {
  239. dol_print_error($this->db);
  240. }
  241. }
  242. }
  243. }