websiteaccount_card.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2023 Lionel Vessiller <lvessiller@open-dsi.fr>
  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/website/websiteaccount_card.php
  20. * \ingroup website
  21. * \brief Page to create/edit/view thirdparty website account
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/website/lib/websiteaccount.lib.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("website", "other"));
  31. // Get parameters
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alpha');
  34. $action = GETPOST('action', 'aZ09');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $cancel = GETPOST('cancel', 'aZ09');
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. // Initialize technical objects
  39. $object = new SocieteAccount($db);
  40. $extrafields = new ExtraFields($db);
  41. $diroutputmassaction = $conf->website->dir_output.'/temp/massgeneration/'.$user->id;
  42. $hookmanager->initHooks(array($object->element.'card', 'globalcard')); // Note that conf->hooks_modules contains array
  43. // Fetch optionals attributes and labels
  44. $extrafields->fetch_name_optionals_label($object->table_element);
  45. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  46. // Initialize array of search criterias
  47. $search_all = GETPOST("search_all", 'alpha');
  48. $search = array();
  49. foreach ($object->fields as $key => $val) {
  50. if (GETPOST('search_'.$key, 'alpha')) {
  51. $search[$key] = GETPOST('search_'.$key, 'alpha');
  52. }
  53. }
  54. if (empty($action) && empty($id) && empty($ref)) {
  55. $action = 'view';
  56. }
  57. // Load object
  58. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  59. // Security check
  60. //if ($user->socid > 0) accessforbidden();
  61. //if ($user->socid > 0) $socid = $user->socid;
  62. //$result = restrictedArea($user, 'website', $id);
  63. $permissiontoaccess = (isModEnabled('website') && $user->hasRight('website', 'read')) || isModEnabled('webportal');
  64. if (!$permissiontoaccess) {
  65. accessforbidden('NotAllowed');
  66. }
  67. // Permissions
  68. $permissiontocreate = 0;
  69. $permissiontodelete = 0;
  70. // permissions from object type of site
  71. if ($object->id > 0) {
  72. if ($object->site == 'dolibarr_website') {
  73. $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write');
  74. $permissiontodelete = isModEnabled('website') && $user->hasRight('website', 'delete');
  75. } elseif ($object->site == 'dolibarr_portal') {
  76. $permissiontocreate = isModEnabled('webportal') && $user->hasRight('webportal', 'write');
  77. }
  78. } else {
  79. $permissiontocreate = isModEnabled('website') && $user->hasRight('website', 'write') || isModEnabled('webportal') && $user->hasRight('webportal', 'write');
  80. }
  81. $permissionnote = $permissiontocreate; // Used by the include of actions_setnotes.inc.php
  82. $permissiondellink = $permissiontocreate; // Used by the include of actions_dellink.inc.php
  83. $permissiontoadd = $permissiontocreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  84. // check access from type of site on create, edit, delete (other than view)
  85. $site_type_js = '';
  86. if (!empty($action) && $action != 'view') {
  87. if (!empty($object->fields['site']['arrayofkeyval'])) {
  88. if (isset($object->fields['site']['arrayofkeyval']['dolibarr_website'])) {
  89. if ($action == 'delete' || $action == 'confirm_delete') {
  90. if (!$user->hasRight('website', 'delete')) {
  91. unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
  92. }
  93. } else {
  94. if (!$user->hasRight('website', 'write')) {
  95. unset($object->fields['site']['arrayofkeyval']['dolibarr_website']);
  96. }
  97. }
  98. }
  99. if (isset($object->fields['site']['arrayofkeyval']['dolibarr_portal'])) {
  100. if (!$user->hasRight('webportal', 'write')) {
  101. unset($object->fields['site']['arrayofkeyval']['dolibarr_portal']);
  102. }
  103. }
  104. }
  105. if (empty($object->fields['site']['arrayofkeyval'])) {
  106. accessforbidden('NotAllowed');
  107. }
  108. if ($object->id > 0) { // update or delete or other than create
  109. // check user has the right to modify this type of website
  110. if (!key_exists($object->site, $object->fields['site']['arrayofkeyval'])) {
  111. accessforbidden('NotAllowed');
  112. }
  113. }
  114. }
  115. /*
  116. * Actions
  117. */
  118. $parameters = array();
  119. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  120. if ($reshook < 0) {
  121. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  122. }
  123. if (empty($reshook)) {
  124. $error = 0;
  125. $backurlforlist = dol_buildpath('/societe/website.php', 1).'?id='.$object->fk_soc;
  126. // Actions cancel, add, update or delete
  127. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  128. // Actions when printing a doc from card
  129. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  130. // Actions to send emails
  131. $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
  132. $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
  133. $trackid = 'websiteaccount'.$object->id;
  134. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  135. }
  136. /*
  137. * View
  138. */
  139. $form = new Form($db);
  140. $formfile = new FormFile($db);
  141. $title = $langs->trans("WebsiteAccount");
  142. $help_url = '';
  143. llxHeader('', $title, $help_url);
  144. // prepare output js
  145. $out_js = '';
  146. if ($action == 'create' || $action == 'edit') {
  147. if (!empty($object->fields['site']['visible']) && !empty($object->fields['fk_website']['visible'])) {
  148. $site_type_js = 'function siteTypeChange(site_type) {';
  149. $site_type_js .= ' if (site_type == "dolibarr_website") {';
  150. $site_type_js .= ' jQuery("tr.field_fk_website").show();';
  151. $site_type_js .= ' } else {';
  152. $site_type_js .= ' jQuery("select#fk_website").val("-1").change();';
  153. $site_type_js .= ' jQuery("tr.field_fk_website").hide();';
  154. $site_type_js .= ' }';
  155. $site_type_js .= '}';
  156. $site_type_js .= 'jQuery(document).ready(function(){';
  157. $site_type_js .= ' siteTypeChange(jQuery("#site").val());';
  158. $site_type_js .= ' jQuery("#site").change(function(){';
  159. $site_type_js .= ' siteTypeChange(this.value);';
  160. $site_type_js .= ' });';
  161. $site_type_js .= '});';
  162. $out_js .= '<script type"text/javascript">';
  163. $out_js .= $site_type_js;
  164. $out_js .= '</script>';
  165. }
  166. }
  167. // Part to create
  168. if ($action == 'create') {
  169. if (empty($permissiontoadd)) {
  170. accessforbidden('NotEnoughPermissions', 0, 1);
  171. }
  172. print load_fiche_titre($langs->trans("NewWebsiteAccount", $langs->transnoentitiesnoconv("WebsiteAccount")));
  173. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  174. print '<input type="hidden" name="token" value="'.newToken().'">';
  175. print '<input type="hidden" name="action" value="add">';
  176. if ($backtopage) {
  177. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  178. }
  179. if ($backtopageforcancel) {
  180. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  181. }
  182. if ($backtopagejsfields) {
  183. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  184. }
  185. if ($dol_openinpopup) {
  186. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  187. }
  188. print dol_get_fiche_head(array(), '');
  189. print '<table class="border centpercent tableforfieldcreate">'."\n";
  190. // Common attributes
  191. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  192. // Other attributes
  193. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  194. print '</table>'."\n";
  195. print dol_get_fiche_end();
  196. print $form->buttonsSaveCancel("Create");
  197. print '</form>';
  198. print $out_js;
  199. }
  200. // Part to edit record
  201. if (($id || $ref) && $action == 'edit') {
  202. print load_fiche_titre($langs->trans("WebsiteAccount"));
  203. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  204. print '<input type="hidden" name="token" value="'.newToken().'">';
  205. print '<input type="hidden" name="action" value="update">';
  206. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  207. print '<input type="hidden" name="id" value="'.$object->id.'">';
  208. print dol_get_fiche_head();
  209. print '<table class="border centpercent tableforfieldedit">'."\n";
  210. // Common attributes
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  212. // Other attributes
  213. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  214. print '</table>';
  215. print dol_get_fiche_end();
  216. print $form->buttonsSaveCancel();
  217. print '</form>';
  218. print $out_js;
  219. }
  220. // Part to show record
  221. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  222. if ($object->fk_soc > 0 && empty($socid)) {
  223. $socid = $object->fk_soc;
  224. }
  225. //$res = $object->fetch_optionals();
  226. $head = websiteaccountPrepareHead($object);
  227. print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, 'websiteaccount@website');
  228. $formconfirm = '';
  229. // Confirmation to delete
  230. if ($action == 'delete') {
  231. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
  232. }
  233. // Call Hook formConfirm
  234. $parameters = array('formConfirm' => $formconfirm);
  235. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  236. if (empty($reshook)) {
  237. $formconfirm .= $hookmanager->resPrint;
  238. } elseif ($reshook > 0) {
  239. $formconfirm = $hookmanager->resPrint;
  240. }
  241. // Print form confirm
  242. print $formconfirm;
  243. // Object card
  244. // ------------------------------------------------------------
  245. $linkback = '';
  246. if ($socid) {
  247. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
  248. }
  249. //if ($fk_website) {
  250. // $linkback = '<a href="'.DOL_URL_ROOT.'/website/website_card.php?fk_website='.$fk_website.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  251. //}
  252. $morehtmlref = '<div class="refidno">';
  253. /*
  254. // Ref bis
  255. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', 0, 1);
  256. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->hasRight('website', 'write'), 'string', '', null, null, '', 1);
  257. // Thirdparty
  258. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  259. // Project
  260. if (isModEnabled('project'))
  261. {
  262. $langs->load("projects");
  263. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  264. if ($user->hasRight('website', 'write'))
  265. {
  266. if ($action != 'classify')
  267. {
  268. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  269. if ($action == 'classify') {
  270. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  271. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  272. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  273. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  274. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  275. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  276. $morehtmlref.='</form>';
  277. } else {
  278. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  279. }
  280. }
  281. } else {
  282. if (!empty($object->fk_project)) {
  283. $proj = new Project($db);
  284. $proj->fetch($object->fk_project);
  285. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  286. $morehtmlref.=$proj->ref;
  287. $morehtmlref.='</a>';
  288. } else {
  289. $morehtmlref.='';
  290. }
  291. }
  292. }
  293. */
  294. $morehtmlref .= '</div>';
  295. if ($socid > 0) {
  296. $object->next_prev_filter = 'te.fk_soc = '.((int) $socid);
  297. }
  298. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  299. print '<div class="fichecenter">';
  300. print '<div class="fichehalfleft">';
  301. print '<div class="underbanner clearboth"></div>';
  302. print '<table class="border centpercent tableforfield">'."\n";
  303. // Common attributes
  304. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  305. // Other attributes
  306. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  307. print '</table>';
  308. print '</div>';
  309. print '</div>';
  310. print '<div class="clearboth"></div>';
  311. print dol_get_fiche_end();
  312. // Buttons for actions
  313. if ($action != 'presend' && $action != 'editline') {
  314. print '<div class="tabsAction">'."\n";
  315. $parameters = array();
  316. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  317. if ($reshook < 0) {
  318. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  319. }
  320. if (empty($reshook)) {
  321. // Send
  322. if (empty($user->socid)) {
  323. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
  324. }
  325. // Clone
  326. if ($permissiontoadd) {
  327. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
  328. }
  329. /*
  330. if ($user->rights->sellyoursaas->create)
  331. {
  332. if ($object->status == 1)
  333. {
  334. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a></div>'."\n";
  335. }
  336. else
  337. {
  338. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a></div>'."\n";
  339. }
  340. }
  341. */
  342. // Delete
  343. $params = array();
  344. print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, $params);
  345. }
  346. print '</div>'."\n";
  347. }
  348. // Select mail models is same action as presend
  349. if (GETPOST('modelselected')) {
  350. $action = 'presend';
  351. }
  352. if ($action != 'presend') {
  353. print '<div class="fichecenter"><div class="fichehalfleft">';
  354. print '<a name="builddoc"></a>'; // ancre
  355. print '</div><div class="fichehalfright">';
  356. /*
  357. $MAXEVENT = 10;
  358. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
  359. // List of actions on element
  360. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  361. $formactions = new FormActions($db);
  362. $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
  363. */
  364. print '</div></div>';
  365. }
  366. // Presend form
  367. $modelmail = 'websiteaccount';
  368. $defaulttopic = 'Information';
  369. $diroutput = $conf->website->dir_output;
  370. $trackid = 'websiteaccount'.$object->id;
  371. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  372. }
  373. // End of page
  374. llxFooter();
  375. $db->close();