storageinventory.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/product/inventory/class/inventory.class.php';
  3. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/utils/globalconst.class.php';
  4. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/utils/emailtemplatehandler.php';
  5. include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
  6. class StorageInventory extends Inventory
  7. {
  8. public $statuses = [];
  9. const EMAIL_TEMPLATE = 'ScrapOrfaultyDeviceTemplate';
  10. const GLOBAL_CONF_SEND_TO_EMAIL = 'DEVICE_ALERT_EMAIL';
  11. const GLOBAL_CONF_EMAIL_FROM = 'BBUS_INVOICE_PRINTING_ALERT_EMAIL_FROM';
  12. function sendMail($status, $ticket_id): void
  13. {
  14. $const = new GlobalConst;
  15. $recipients = $const->load(self::GLOBAL_CONF_SEND_TO_EMAIL);
  16. $emailFrom = $const->load(self::GLOBAL_CONF_EMAIL_FROM);
  17. if (!empty($recipients) && !empty($emailFrom)) {
  18. $emailTemplateHandler = new EmailTemplateHandler;
  19. $template = $emailTemplateHandler->load(self::EMAIL_TEMPLATE);
  20. $templateObject = new stdClass();
  21. foreach ($template as $key => $value) {
  22. $templateObject->$key = $value;
  23. }
  24. if ($templateObject) {
  25. $vars = [
  26. '__STATUS__ ' => $status,
  27. '__TICKETID__' => $ticket_id,
  28. ];
  29. $template = $emailTemplateHandler->prepareTemplate($templateObject, $vars);
  30. $mail = new CMailFile(
  31. $template->topic,
  32. $recipients,
  33. $emailFrom,
  34. $template->content,
  35. null,
  36. null,
  37. null,
  38. '',
  39. '',
  40. 0,
  41. 1
  42. );
  43. // Send Email
  44. $mail->sendfile();
  45. if ($mail->error) {
  46. print_r($mail->error);
  47. exit;
  48. // do something...
  49. dol_syslog('CRON ALERT EMAIL ERROR: ' . $mail->error, LOG_ERR);
  50. }
  51. }
  52. }
  53. }
  54. /**
  55. * Load object in memory from the database
  56. *
  57. * @param int $id Id object
  58. * @param string $ref Ref
  59. * @param string $morewhere More SQL filters (' AND ...')
  60. * @return int <0 if KO, 0 if not found, >0 if OK
  61. */
  62. public function fetchByWarehouse($id, $ref = null, $morewhere = '')
  63. {
  64. $result = $this->fetchCommon($id, $ref, $morewhere);
  65. return $result;
  66. }
  67. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  68. /**
  69. * Return the status
  70. *
  71. * @param int $status Id status
  72. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto, 6=Long label + Picto
  73. * @return string Label of status
  74. */
  75. public static function LibStatut($status, $mode = 0)
  76. {
  77. // phpcs:enable
  78. global $langs;
  79. global $db;
  80. $statusObj = new Statuses($db);
  81. $statuses = $statusObj::getStatusids($db);
  82. $labelStatus = array();
  83. $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  84. $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
  85. $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
  86. $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
  87. foreach($statuses as $key => $val){
  88. $labelStatus[$key] = $val;
  89. $labelStatusShort[$key] = $val;
  90. }
  91. $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  92. $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
  93. $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
  94. $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
  95. $statusType = 'status'.$status;
  96. if ($status == self::STATUS_RECORDED) {
  97. $statusType = 'status6';
  98. }
  99. return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
  100. }
  101. /**
  102. * Function to show lines of extrafields with output datas.
  103. * This function is responsible to output the <tr> and <td> according to correct number of columns received into $params['colspan'] or <div> according to $display_type
  104. *
  105. * @param Extrafields $extrafields Extrafield Object
  106. * @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield
  107. * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
  108. * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
  109. * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
  110. * @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example.
  111. * @param string $display_type "card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
  112. * @return string String with html content to show
  113. */
  114. public function showOptionalsRollerstorage($inventory_id, $extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0, $display_type = 'card')
  115. {
  116. global $db, $conf, $langs, $action, $form, $hookmanager;
  117. if (!is_object($form)) {
  118. $form = new Form($db);
  119. }
  120. if (!is_object($extrafields)) {
  121. dol_syslog('Bad parameter extrafields for showOptionals', LOG_ERR);
  122. return 'Bad parameter extrafields for showOptionals';
  123. }
  124. if (!is_array($extrafields->attributes[$this->table_element])) {
  125. dol_syslog("extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
  126. }
  127. $out = '';
  128. $parameters = array();
  129. $reshook = $hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
  130. if (empty($reshook)) {
  131. if (is_array($extrafields->attributes[$this->table_element]) && key_exists('label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) {
  132. $out .= "\n";
  133. $out .= '<!-- commonobject:showOptionals --> ';
  134. $out .= "\n";
  135. $extrafields_collapse_num = '';
  136. $e = 0;
  137. foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $label) {
  138. // Show only the key field in params
  139. if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) {
  140. continue;
  141. }
  142. // Test on 'enabled' ('enabled' is different than 'list' = 'visibility')
  143. $enabled = 1;
  144. if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key])) {
  145. $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1, 1, '1');
  146. }
  147. if (empty($enabled)) {
  148. continue;
  149. }
  150. $visibility = 1;
  151. if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key])) {
  152. $visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1, 1, '1');
  153. }
  154. $perms = 1;
  155. if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) {
  156. $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1, 1, '1');
  157. }
  158. if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) {
  159. continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
  160. } elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) {
  161. continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
  162. } elseif ($mode == 'view' && empty($visibility)) {
  163. continue;
  164. }
  165. if (empty($perms)) {
  166. continue;
  167. }
  168. // Load language if required
  169. if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
  170. $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
  171. }
  172. $colspan = 0;
  173. if (is_array($params) && count($params) > 0 && $display_type == 'card') {
  174. if (array_key_exists('cols', $params)) {
  175. $colspan = $params['cols'];
  176. } elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
  177. $reg = array();
  178. if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
  179. $colspan = $reg[1];
  180. } else {
  181. $colspan = $params['colspan'];
  182. }
  183. }
  184. }
  185. $colspan = intval($colspan);
  186. switch ($mode) {
  187. case "view":
  188. $value = ((!empty($this->array_options) && array_key_exists("options_" . $key . $keysuffix, $this->array_options)) ? $this->array_options["options_" . $key . $keysuffix] : null); // Value may be cleaned or formated later
  189. break;
  190. case "create":
  191. case "edit":
  192. // We get the value of property found with GETPOST so it takes into account:
  193. // default values overwrite, restore back to list link, ... (but not 'default value in database' of field)
  194. $check = 'alphanohtml';
  195. if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) {
  196. $check = 'restricthtml';
  197. }
  198. $getposttemp = GETPOST($keyprefix . 'options_' . $key . $keysuffix, $check, 3); // GETPOST can get value from GET, POST or setup of default values overwrite.
  199. // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
  200. if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix)) {
  201. if (is_array($getposttemp)) {
  202. // $getposttemp is an array but following code expects a comma separated string
  203. $value = implode(",", $getposttemp);
  204. } else {
  205. $value = $getposttemp;
  206. }
  207. } else {
  208. $value = (!empty($this->array_options["options_" . $key]) ? $this->array_options["options_" . $key] : ''); // No GET, no POST, no default value, so we take value of object.
  209. }
  210. //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value);
  211. break;
  212. }
  213. // Output value of the current field
  214. if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') {
  215. $extrafields_collapse_num = '';
  216. $extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
  217. if (!empty($extrafield_param) && is_array($extrafield_param)) {
  218. $extrafield_param_list = array_keys($extrafield_param['options']);
  219. if (count($extrafield_param_list) > 0) {
  220. $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
  221. if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
  222. $extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
  223. }
  224. }
  225. }
  226. // if colspan=0 or 1, the second column is not extended, so the separator must be on 2 columns
  227. $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
  228. } else {
  229. $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
  230. $csstyle = '';
  231. if (is_array($params) && count($params) > 0) {
  232. if (array_key_exists('class', $params)) {
  233. $class .= $params['class'] . ' ';
  234. }
  235. if (array_key_exists('style', $params)) {
  236. $csstyle = $params['style'];
  237. }
  238. }
  239. // add html5 elements
  240. $domData = ' data-element="extrafield"';
  241. $domData .= ' data-targetelement="' . $this->element . '"';
  242. $domData .= ' data-targetid="' . $this->id . '"';
  243. $html_id = (empty($this->id) ? '' : 'extrarow-' . $this->element . '_' . $key . '_' . $this->id);
  244. if ($display_type == 'card') {
  245. if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
  246. $colspan = 0;
  247. }
  248. if ($action == 'selectlines') {
  249. $colspan++;
  250. }
  251. }
  252. // Convert date into timestamp format (value in memory must be a timestamp)
  253. if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date'))) {
  254. $datenotinstring = null;
  255. if (array_key_exists('options_' . $key, $this->array_options)) {
  256. $datenotinstring = $this->array_options['options_' . $key];
  257. if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
  258. $datenotinstring = $this->db->jdate($datenotinstring);
  259. }
  260. }
  261. $datekey = $keyprefix . 'options_' . $key . $keysuffix;
  262. $value = (GETPOSTISSET($datekey)) ? dol_mktime(12, 0, 0, GETPOST($datekey . 'month', 'int', 3), GETPOST($datekey . 'day', 'int', 3), GETPOST($datekey . 'year', 'int', 3)) : $datenotinstring;
  263. }
  264. if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('datetime'))) {
  265. $datenotinstring = null;
  266. if (array_key_exists('options_' . $key, $this->array_options)) {
  267. $datenotinstring = $this->array_options['options_' . $key];
  268. if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
  269. $datenotinstring = $this->db->jdate($datenotinstring);
  270. }
  271. }
  272. $timekey = $keyprefix . 'options_' . $key . $keysuffix;
  273. $value = (GETPOSTISSET($timekey)) ? dol_mktime(GETPOST($timekey . 'hour', 'int', 3), GETPOST($timekey . 'min', 'int', 3), GETPOST($timekey . 'sec', 'int', 3), GETPOST($timekey . 'month', 'int', 3), GETPOST($timekey . 'day', 'int', 3), GETPOST($timekey . 'year', 'int', 3), 'tzuserrel') : $datenotinstring;
  274. }
  275. // Convert float submited string into real php numeric (value in memory must be a php numeric)
  276. if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) {
  277. if (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) {
  278. $value = price2num($value);
  279. } elseif (isset($this->array_options['options_' . $key])) {
  280. $value = $this->array_options['options_' . $key];
  281. }
  282. }
  283. // HTML, text, select, integer and varchar: take into account default value in database if in create mode
  284. if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'varchar', 'select', 'int', 'boolean'))) {
  285. if ($action == 'create') {
  286. $value = (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element]['default'][$key];
  287. }
  288. }
  289. $labeltoshow = $langs->trans($label);
  290. $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
  291. if ($display_type == 'card') {
  292. $out .= '<tr ' . ($html_id ? 'id="' . $html_id . '" ' : '') . $csstyle . ' class="field_options_' . $key . ' ' . $class . $this->element . '_extras_' . $key . ' trextrafields_collapse' . $extrafields_collapse_num . (!empty($this->id) ? '_' . $this->id : '') . '" ' . $domData . ' >';
  293. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER) && ($action == 'view' || $action == 'valid' || $action == 'editline' || $action == 'confirm_valid' || $action == 'confirm_cancel')) {
  294. $out .= '<td></td>';
  295. }
  296. $out .= '<td class="titlefieldcreate wordbreak';
  297. } elseif ($display_type == 'line') {
  298. $out .= '<div ' . ($html_id ? 'id="' . $html_id . '" ' : '') . $csstyle . ' class="fieldline_options_' . $key . ' ' . $class . $this->element . '_extras_' . $key . ' trextrafields_collapse' . $extrafields_collapse_num . (!empty($this->id) ? '_' . $this->id : '') . '" ' . $domData . ' >';
  299. $out .= '<div style="display: inline-block; padding-right:4px" class="titlefieldcreate wordbreak';
  300. }
  301. //$out .= "titlefield";
  302. //if (GETPOST('action', 'restricthtml') == 'create') $out.='create';
  303. // BUG #11554 : For public page, use red dot for required fields, instead of bold label
  304. $tpl_context = isset($params["tpl_context"]) ? $params["tpl_context"] : "none";
  305. if ($tpl_context != "public") { // Public page : red dot instead of fieldrequired characters
  306. if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
  307. $out .= ' fieldrequired';
  308. }
  309. }
  310. $out .= '">';
  311. if ($tpl_context == "public") { // Public page : red dot instead of fieldrequired characters
  312. if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
  313. $out .= $form->textwithpicto($labeltoshow, $helptoshow);
  314. } else {
  315. $out .= $labeltoshow;
  316. }
  317. if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
  318. $out .= '&nbsp;<span style="color: red">*</span>';
  319. }
  320. } else {
  321. if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
  322. $out .= $form->textwithpicto($labeltoshow, $helptoshow);
  323. } else {
  324. $out .= $labeltoshow;
  325. }
  326. }
  327. $out .= ($display_type == 'card' ? '</td>' : '</div>');
  328. $html_id = !empty($this->id) ? $this->element . '_extras_' . $key . '_' . $this->id : '';
  329. if ($display_type == 'card') {
  330. // a first td column was already output (and may be another on before if MAIN_VIEW_LINE_NUMBER set), so this td is the next one
  331. $out .= '<td ' . ($html_id ? 'id="' . $html_id . '" ' : '') . ' class="valuefieldcreate ' . $this->element . '_extras_' . $key . '" ' . ($colspan ? ' colspan="' . $colspan . '"' : '') . '>';
  332. } elseif ($display_type == 'line') {
  333. $out .= '<div ' . ($html_id ? 'id="' . $html_id . '" ' : '') . ' style="display: inline-block" class="valuefieldcreate ' . $this->element . '_extras_' . $key . ' extra_inline_' . $extrafields->attributes[$this->table_element]['type'][$key] . '">';
  334. }
  335. switch ($mode) {
  336. case "view":
  337. $out .= $extrafields->showOutputField($key, $value, '', $this->table_element);
  338. break;
  339. case "create":
  340. if ($key == 'assigned_device') {
  341. $out .= $extrafields->showInputField($key, $value, ' AND main.fk_warehouse = ' . $inventory_id, $keysuffix, '', 0, $this->id, $this->table_element);
  342. } else {
  343. $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element);
  344. }
  345. break;
  346. case "edit":
  347. if ($key == 'assigned_device') {
  348. $out .= $extrafields->showInputField($key, $value, ' AND main.fk_warehouse = ' . $inventory_id, $keysuffix, '', 0, $this->id, $this->table_element);
  349. } else {
  350. $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element);
  351. }
  352. break;
  353. }
  354. $out .= ($display_type == 'card' ? '</td>' : '</div>');
  355. if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
  356. $out .= ($display_type == 'card' ? '</tr>' : '</div>');
  357. } else {
  358. $out .= ($display_type == 'card' ? '</tr>' : '</div>');
  359. }
  360. $e++;
  361. }
  362. }
  363. $out .= "\n";
  364. // Add code to manage list depending on others
  365. if (!empty($conf->use_javascript_ajax)) {
  366. $out .= $this->getJSListDependancies();
  367. }
  368. $out .= '<!-- commonobject:showOptionals end --> ' . "\n";
  369. }
  370. }
  371. $out .= $hookmanager->resPrint;
  372. return $out;
  373. }
  374. /**
  375. * @param string $type Type for prefix
  376. * @return string Javacript code to manage dependency
  377. */
  378. public function getJSListDependancies($type = '_extra')
  379. {
  380. $out = '
  381. <script>
  382. jQuery(document).ready(function() {
  383. function showOptions' . $type . '(child_list, parent_list, orig_select)
  384. {
  385. var val = $("select[name=\""+parent_list+"\"]").val();
  386. var parentVal = parent_list + ":" + val;
  387. if(typeof val == "string"){
  388. if(val != "") {
  389. var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
  390. $("select[name=\""+child_list+"\"] option[parent]").remove();
  391. $("select[name=\""+child_list+"\"]").append(options);
  392. } else {
  393. var options = orig_select.find("option[parent]").clone();
  394. $("select[name=\""+child_list+"\"] option[parent]").remove();
  395. $("select[name=\""+child_list+"\"]").append(options);
  396. }
  397. } else if(val > 0) {
  398. var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
  399. $("select[name=\""+child_list+"\"] option[parent]").remove();
  400. $("select[name=\""+child_list+"\"]").append(options);
  401. } else {
  402. var options = orig_select.find("option[parent]").clone();
  403. $("select[name=\""+child_list+"\"] option[parent]").remove();
  404. $("select[name=\""+child_list+"\"]").append(options);
  405. }
  406. }
  407. function setListDependencies' . $type . '() {
  408. jQuery("select option[parent]").parent().each(function() {
  409. var orig_select = {};
  410. var child_list = $(this).attr("name");
  411. orig_select[child_list] = $(this).clone();
  412. var parent = $(this).find("option[parent]:first").attr("parent");
  413. var infos = parent.split(":");
  414. var parent_list = infos[0];
  415. //Hide daughters lists
  416. if ($("#"+child_list).val() == 0 && ($("#"+parent_list).val() == 0 || $("#"+parent_list).val() == undefined)){
  417. $("#"+child_list).hide();
  418. //Show mother lists
  419. } else if ($("#"+parent_list).val() != 0){
  420. $("#"+parent_list).show();
  421. }
  422. //Show the child list if the parent list value is selected
  423. $("select[name=\""+parent_list+"\"]").click(function() {
  424. if ($(this).val() != 0){
  425. $("#"+child_list).show()
  426. }
  427. });
  428. //When we change parent list
  429. $("select[name=\""+parent_list+"\"]").change(function() {
  430. showOptions' . $type . '(child_list, parent_list, orig_select[child_list]);
  431. //Select the value 0 on child list after a change on the parent list
  432. $("#"+child_list).val(0).trigger("change");
  433. //Hide child lists if the parent value is set to 0
  434. if ($(this).val() == 0){
  435. $("#"+child_list).hide();
  436. }
  437. });
  438. });
  439. }
  440. setListDependencies' . $type . '();
  441. });
  442. </script>' . "\n";
  443. return $out;
  444. }
  445. }