1<?php 2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> 3 * Copyright (C) ---Put here your own copyright and developer email--- 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 <http://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * \file htdocs/zapier/myobject_card.php 21 * \ingroup mymodule 22 * \brief Page to create/edit/view myobject 23 */ 24 25// Load Dolibarr environment 26require '../main.inc.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 29dol_include_once('/mymodule/class/myobject.class.php'); 30dol_include_once('/mymodule/lib/mymodule_myobject.lib.php'); 31 32// Load translation files required by the page 33$langs->loadLangs(array("mymodule@mymodule", "other")); 34 35// Get parameters 36$id = GETPOST('id', 'int'); 37$ref = GETPOST('ref', 'alpha'); 38$action = GETPOST('action', 'aZ09'); 39$confirm = GETPOST('confirm', 'alpha'); 40$cancel = GETPOST('cancel', 'aZ09'); 41$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'zapiercard'; // To manage different context of search 42$backtopage = GETPOST('backtopage', 'alpha'); 43 44// Initialize technical objects 45$object = new MyObject($db); 46$extrafields = new ExtraFields($db); 47$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id; 48$hookmanager->initHooks(array('myobjectcard', 'globalcard')); // Note that conf->hooks_modules contains array 49 50// Fetch optionals attributes and labels 51$extrafields->fetch_name_optionals_label($object->table_element); 52 53$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); 54 55// Initialize array of search criterias 56$search_all = GETPOST("search_all", 'alpha'); 57$search = array(); 58foreach ($object->fields as $key => $val) { 59 if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); 60} 61 62if (empty($action) && empty($id) && empty($ref)) $action = 'view'; 63 64// Load object 65include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals 66 67// Security check - Protection if external user 68//if ($user->socid > 0) accessforbidden(); 69//if ($user->socid > 0) $socid = $user->socid; 70//$isdraft = (($object->statut == MyObject::STATUS_DRAFT) ? 1 : 0); 71//$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); 72 73 74/* 75 * Actions 76 * 77 * Put here all code to do according to value of "action" parameter 78 */ 79 80$parameters = array(); 81$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 82if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 83 84if (empty($reshook)) { 85 $error = 0; 86 87 $permissiontoadd = $user->rights->mymodule->write; 88 $permissiontodelete = $user->rights->mymodule->delete || ($permissiontoadd && $object->status == 0); 89 $backurlforlist = dol_buildpath('/mymodule/myobject_list.php', 1); 90 if (empty($backtopage)) { 91 if (empty($id)) $backtopage = $backurlforlist; 92 else $backtopage = dol_buildpath('/mymodule/myobject_card.php', 1).($id > 0 ? $id : '__ID__'); 93 } 94 $triggermodname = 'MYMODULE_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record 95 96 // Actions cancel, add, update, delete or clone 97 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; 98 99 // Actions when linking object each other 100 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; 101 102 // Actions when printing a doc from card 103 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; 104} 105 106 107 108 109/* 110 * View 111 * 112 * Put here all code to build page 113 */ 114 115$form = new Form($db); 116$formfile = new FormFile($db); 117 118llxHeader('', 'MyObject', ''); 119 120// Example : Adding jquery code 121print '<script type="text/javascript" language="javascript"> 122jQuery(document).ready(function() { 123 function init_myfunc() 124 { 125 jQuery("#myid").removeAttr(\'disabled\'); 126 jQuery("#myid").attr(\'disabled\',\'disabled\'); 127 } 128 init_myfunc(); 129 jQuery("#mybutton").click(function() { 130 init_myfunc(); 131 }); 132}); 133</script>'; 134 135 136// Part to create 137if ($action == 'create') { 138 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("MyObject"))); 139 140 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 141 print '<input type="hidden" name="token" value="'.newToken().'">'; 142 print '<input type="hidden" name="action" value="add">'; 143 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 144 145 print dol_get_fiche_head(array(), ''); 146 147 print '<table class="border centpercent">'."\n"; 148 149 // Common attributes 150 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; 151 152 // Other attributes 153 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; 154 155 print '</table>'."\n"; 156 157 print dol_get_fiche_end(); 158 159 print '<div class="center">'; 160 print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">'; 161 print ' '; 162 print '<input type="'.($backtopage ? "submit" : "button").'" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage 163 print '</div>'; 164 165 print '</form>'; 166} 167 168// Part to edit record 169if (($id || $ref) && $action == 'edit') { 170 print load_fiche_titre($langs->trans("MyObject")); 171 172 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; 173 print '<input type="hidden" name="token" value="'.newToken().'">'; 174 print '<input type="hidden" name="action" value="update">'; 175 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 176 print '<input type="hidden" name="id" value="'.$object->id.'">'; 177 178 print dol_get_fiche_head(); 179 180 print '<table class="border centpercent">'."\n"; 181 182 // Common attributes 183 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; 184 185 // Other attributes 186 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; 187 188 print '</table>'; 189 190 print dol_get_fiche_end(); 191 192 print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">'; 193 print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; 194 print '</div>'; 195 196 print '</form>'; 197} 198 199// Part to show record 200if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { 201 $res = $object->fetch_optionals(); 202 203 $head = myobjectPrepareHead($object); 204 print dol_get_fiche_head($head, 'card', $langs->trans("MyObject"), -1, 'myobject@mymodule'); 205 206 $formconfirm = ''; 207 208 // Confirmation to delete 209 if ($action == 'delete') { 210 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteMyObject'), 'confirm_delete', '', 0, 1); 211 } 212 213 // Clone confirmation 214 if ($action == 'clone') { 215 // Create an array for form 216 $formquestion = array(); 217 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); 218 } 219 220 // Confirmation of action xxxx 221 if ($action == 'xxx') { 222 $formquestion = array(); 223 /* 224 $forcecombo=0; 225 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy 226 $formquestion = array( 227 // 'text' => $langs->trans("ConfirmClone"), 228 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), 229 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), 230 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo)) 231 ); 232 */ 233 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220); 234 } 235 236 // Call Hook formConfirm 237 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); 238 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 239 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; 240 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; 241 242 // Print form confirm 243 print $formconfirm; 244 245 246 // Object card 247 // ------------------------------------------------------------ 248 $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 249 250 $morehtmlref = '<div class="refidno">'; 251 /* 252 // Ref bis 253 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', 0, 1); 254 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', null, null, '', 1); 255 // Thirdparty 256 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); 257 // Project 258 if (! empty($conf->projet->enabled)) 259 { 260 $langs->load("projects"); 261 $morehtmlref.='<br>'.$langs->trans('Project') . ' '; 262 if ($user->rights->mymodule->write) 263 { 264 if ($action != 'classify') 265 $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; 266 if ($action == 'classify') { 267 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 268 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 269 $morehtmlref.='<input type="hidden" name="action" value="classin">'; 270 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">'; 271 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1); 272 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 273 $morehtmlref.='</form>'; 274 } else { 275 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 276 } 277 } else { 278 if (! empty($object->fk_project)) { 279 $proj = new Project($db); 280 $proj->fetch($object->fk_project); 281 $morehtmlref.=$proj->getNomUrl(); 282 } else { 283 $morehtmlref.=''; 284 } 285 } 286 } 287 */ 288 $morehtmlref .= '</div>'; 289 290 291 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); 292 293 294 print '<div class="fichecenter">'; 295 print '<div class="fichehalfleft">'; 296 print '<div class="underbanner clearboth"></div>'; 297 print '<table class="border centpercent">'."\n"; 298 299 // Common attributes 300 //$keyforbreak='fieldkeytoswithonsecondcolumn'; 301 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; 302 303 // Other attributes 304 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; 305 306 print '</table>'; 307 print '</div>'; 308 print '</div>'; 309 310 print '<div class="clearboth"></div><br>'; 311 312 print dol_get_fiche_end(); 313 314 315 // Buttons for actions 316 if ($action != 'presend' && $action != 'editline') { 317 print '<div class="tabsAction">'."\n"; 318 $parameters = array(); 319 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 320 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 321 322 if (empty($reshook)) { 323 // Modify 324 if ($user->rights->mymodule->write) { 325 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n"; 326 } else { 327 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n"; 328 } 329 330 // Clone 331 if ($user->rights->mymodule->write) { 332 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=order">'.$langs->trans("ToClone").'</a></div>'; 333 } 334 335 /* 336 if ($user->rights->mymodule->write) 337 { 338 if ($object->status == 1) 339 { 340 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n"; 341 } 342 else 343 { 344 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n"; 345 } 346 } 347 */ 348 349 if ($user->rights->mymodule->delete) { 350 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n"; 351 } else { 352 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n"; 353 } 354 } 355 print '</div>'."\n"; 356 } 357 358 359 // Select mail models is same action as presend 360 if (GETPOST('modelselected')) { 361 $action = 'presend'; 362 } 363 364 if ($action != 'presend') { 365 print '<div class="fichecenter"><div class="fichehalfleft">'; 366 print '<a name="builddoc"></a>'; // ancre 367 368 // Show links to link elements 369 $linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject')); 370 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); 371 372 373 print '</div><div class="fichehalfright"><div class="ficheaddleft">'; 374 375 $MAXEVENT = 10; 376 377 $morehtmlright = '<a href="'.dol_buildpath('/mymodule/myobject_info.php', 1).'?id='.$object->id.'">'; 378 $morehtmlright .= $langs->trans("SeeAll"); 379 $morehtmlright .= '</a>'; 380 381 // List of actions on element 382 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; 383 $formactions = new FormActions($db); 384 $somethingshown = $formactions->showactions($object, 'myobject', $socid, 1, '', $MAXEVENT, '', $morehtmlright); 385 386 print '</div></div></div>'; 387 } 388} 389 390// End of page 391llxFooter(); 392$db->close(); 393