websiteaccount_card.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/website/websiteaccount_card.php
  19. * \ingroup website
  20. * \brief Page to create/edit/view thirdparty website account
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/website/lib/websiteaccount.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("website", "other"));
  30. // Get parameters
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'aZ09');
  34. $confirm = GETPOST('confirm', 'alpha');
  35. $cancel = GETPOST('cancel', 'aZ09');
  36. $backtopage = GETPOST('backtopage', 'alpha');
  37. // Initialize technical objects
  38. $object = new SocieteAccount($db);
  39. $extrafields = new ExtraFields($db);
  40. $diroutputmassaction = $conf->website->dir_output.'/temp/massgeneration/'.$user->id;
  41. $hookmanager->initHooks(array('websiteaccountcard')); // Note that conf->hooks_modules contains array
  42. // Fetch optionals attributes and labels
  43. $extrafields->fetch_name_optionals_label($object->table_element);
  44. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  45. // Initialize array of search criterias
  46. $search_all = GETPOST("search_all", 'alpha');
  47. $search = array();
  48. foreach ($object->fields as $key => $val) {
  49. if (GETPOST('search_'.$key, 'alpha')) {
  50. $search[$key] = GETPOST('search_'.$key, 'alpha');
  51. }
  52. }
  53. if (empty($action) && empty($id) && empty($ref)) {
  54. $action = 'view';
  55. }
  56. // Load object
  57. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  58. // Security check - Protection if external user
  59. //if ($user->socid > 0) accessforbidden();
  60. //if ($user->socid > 0) $socid = $user->socid;
  61. //$result = restrictedArea($user, 'website', $id);
  62. if (empty($user->rights->websiteaccount->read)) {
  63. accessforbidden('NotAllowed');
  64. }
  65. // Permissions
  66. $permissionnote = $user->rights->websiteaccount->write; // Used by the include of actions_setnotes.inc.php
  67. $permissiondellink = $user->rights->websiteaccount->write; // Used by the include of actions_dellink.inc.php
  68. $permissiontoadd = $user->rights->websiteaccount->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  69. $permissiontodelete = $user->rights->websiteaccount->delete;
  70. /*
  71. * Actions
  72. */
  73. $parameters = array();
  74. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  75. if ($reshook < 0) {
  76. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. }
  78. if (empty($reshook)) {
  79. $error = 0;
  80. $permissiontoadd = $user->rights->website->write;
  81. $permissiontodelete = $user->rights->website->delete;
  82. $backurlforlist = dol_buildpath('/website/websiteaccount_list.php', 1);
  83. // Actions cancel, add, update or delete
  84. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  85. // Actions when printing a doc from card
  86. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  87. // Actions to send emails
  88. $triggersendname = 'WEBSITEACCOUNT_SENTBYMAIL';
  89. $autocopy = 'MAIN_MAIL_AUTOCOPY_WEBSITEACCOUNT_TO';
  90. $trackid = 'websiteaccount'.$object->id;
  91. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  92. }
  93. /*
  94. * View
  95. */
  96. $form = new Form($db);
  97. $formfile = new FormFile($db);
  98. llxHeader('', 'WebsiteAccount', '');
  99. // Part to create
  100. if ($action == 'create') {
  101. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("WebsiteAccount")));
  102. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  103. print '<input type="hidden" name="token" value="'.newToken().'">';
  104. print '<input type="hidden" name="action" value="add">';
  105. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  106. print dol_get_fiche_head();
  107. print '<table class="border centpercent">'."\n";
  108. // Common attributes
  109. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  110. // Other attributes
  111. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  112. print '</table>'."\n";
  113. print dol_get_fiche_end();
  114. print $form->buttonsSaveCancel("Create");
  115. print '</form>';
  116. }
  117. // Part to edit record
  118. if (($id || $ref) && $action == 'edit') {
  119. print load_fiche_titre($langs->trans("WebsiteAccount"));
  120. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  121. print '<input type="hidden" name="action" value="update">';
  122. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  123. print '<input type="hidden" name="id" value="'.$object->id.'">';
  124. print dol_get_fiche_head();
  125. print '<table class="border centpercent">'."\n";
  126. // Common attributes
  127. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  128. // Other attributes
  129. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  130. print '</table>';
  131. print dol_get_fiche_end();
  132. print $form->buttonsSaveCancel();
  133. print '</form>';
  134. }
  135. // Part to show record
  136. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  137. if ($object->fk_soc > 0 && empty($socid)) {
  138. $socid = $object->fk_soc;
  139. }
  140. $res = $object->fetch_optionals();
  141. $head = websiteaccountPrepareHead($object);
  142. print dol_get_fiche_head($head, 'card', $langs->trans("WebsiteAccount"), -1, 'websiteaccount@website');
  143. $formconfirm = '';
  144. // Confirmation to delete
  145. if ($action == 'delete') {
  146. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsiteAccount'), $langs->trans('ConfirmDeleteWebsiteAccount'), 'confirm_delete', '', 0, 1);
  147. }
  148. // Call Hook formConfirm
  149. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  150. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  151. if (empty($reshook)) {
  152. $formconfirm .= $hookmanager->resPrint;
  153. } elseif ($reshook > 0) {
  154. $formconfirm = $hookmanager->resPrint;
  155. }
  156. // Print form confirm
  157. print $formconfirm;
  158. // Object card
  159. // ------------------------------------------------------------
  160. $linkback = '';
  161. if ($socid) {
  162. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/website.php?socid='.$socid.'&restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToListForThirdParty").'</a>';
  163. }
  164. if ($fk_website) {
  165. $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>';
  166. }
  167. $morehtmlref = '<div class="refidno">';
  168. /*
  169. // Ref bis
  170. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->website->creer, 'string', '', 0, 1);
  171. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->website->creer, 'string', '', null, null, '', 1);
  172. // Thirdparty
  173. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  174. // Project
  175. if (isModEnabled('project'))
  176. {
  177. $langs->load("projects");
  178. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  179. if ($user->rights->website->creer)
  180. {
  181. if ($action != 'classify')
  182. {
  183. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  184. if ($action == 'classify') {
  185. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  186. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  187. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  188. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  189. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  190. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  191. $morehtmlref.='</form>';
  192. } else {
  193. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  194. }
  195. }
  196. } else {
  197. if (!empty($object->fk_project)) {
  198. $proj = new Project($db);
  199. $proj->fetch($object->fk_project);
  200. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  201. $morehtmlref.=$proj->ref;
  202. $morehtmlref.='</a>';
  203. } else {
  204. $morehtmlref.='';
  205. }
  206. }
  207. }
  208. */
  209. $morehtmlref .= '</div>';
  210. if ($socid > 0) {
  211. $object->next_prev_filter = 'te.fk_soc = '.((int) $socid);
  212. }
  213. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  214. print '<div class="fichecenter">';
  215. print '<div class="fichehalfleft">';
  216. print '<div class="underbanner clearboth"></div>';
  217. print '<table class="border centpercent">'."\n";
  218. // Common attributes
  219. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  220. // Other attributes
  221. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  222. print '</table>';
  223. print '</div>';
  224. print '</div>';
  225. print '</div>';
  226. print '<div class="clearboth"></div><br>';
  227. print dol_get_fiche_end();
  228. // Buttons for actions
  229. if ($action != 'presend' && $action != 'editline') {
  230. print '<div class="tabsAction">'."\n";
  231. $parameters = array();
  232. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  233. if ($reshook < 0) {
  234. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  235. }
  236. if (empty($reshook)) {
  237. // Send
  238. if (empty($user->socid)) {
  239. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>'."\n";
  240. }
  241. if ($user->rights->website->write) {
  242. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>'."\n";
  243. }
  244. /*
  245. if ($user->rights->sellyoursaas->create)
  246. {
  247. if ($object->status == 1)
  248. {
  249. 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";
  250. }
  251. else
  252. {
  253. 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";
  254. }
  255. }
  256. */
  257. if ($permissiontodelete) {
  258. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  259. }
  260. }
  261. print '</div>'."\n";
  262. }
  263. // Select mail models is same action as presend
  264. if (GETPOST('modelselected')) {
  265. $action = 'presend';
  266. }
  267. if ($action != 'presend') {
  268. print '<div class="fichecenter"><div class="fichehalfleft">';
  269. print '<a name="builddoc"></a>'; // ancre
  270. print '</div><div class="fichehalfright">';
  271. /*
  272. $MAXEVENT = 10;
  273. // List of actions on element
  274. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  275. $formactions = new FormActions($db);
  276. $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
  277. */
  278. print '</div></div>';
  279. }
  280. // Presend form
  281. $modelmail = 'websiteaccount';
  282. $defaulttopic = 'Information';
  283. $diroutput = $conf->website->dir_output;
  284. $trackid = 'websiteaccount'.$object->id;
  285. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  286. }
  287. // End of page
  288. llxFooter();
  289. $db->close();