setup.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. /* Copyright (C) 2004-2020 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/recruitment/admin/setup.php
  19. * \ingroup recruitment
  20. * \brief Recruitment setup page.
  21. */
  22. // Load Dolibarr environment
  23. $res = 0;
  24. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  25. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  26. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  27. }
  28. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  29. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  30. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  31. $i--; $j--;
  32. }
  33. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  34. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  35. }
  36. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  37. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  38. }
  39. // Try main.inc.php using relative path
  40. if (!$res && file_exists("../../main.inc.php")) {
  41. $res = @include "../../main.inc.php";
  42. }
  43. if (!$res && file_exists("../../../main.inc.php")) {
  44. $res = @include "../../../main.inc.php";
  45. }
  46. if (!$res) {
  47. die("Include of main fails");
  48. }
  49. global $langs, $user;
  50. // Libraries
  51. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  52. require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment.lib.php';
  53. require_once DOL_DOCUMENT_ROOT."/recruitment/class/recruitmentjobposition.class.php";
  54. // Translations
  55. $langs->loadLangs(array("admin", "recruitment"));
  56. // Access control
  57. if (!$user->admin) {
  58. accessforbidden();
  59. }
  60. // Parameters
  61. $action = GETPOST('action', 'aZ09');
  62. $backtopage = GETPOST('backtopage', 'alpha');
  63. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  64. $value = GETPOST('value', 'alpha');
  65. $label = GETPOST('label', 'alpha');
  66. $scandir = GETPOST('scan_dir', 'alpha');
  67. $type = 'recruitmentjobposition';
  68. $arrayofparameters = array(
  69. // 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
  70. // 'RECRUITMENT_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
  71. );
  72. $error = 0;
  73. $setupnotempty = 0;
  74. /*
  75. * Actions
  76. */
  77. if ((float) DOL_VERSION >= 6) {
  78. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  79. }
  80. if ($action == 'updateMask') {
  81. $maskconst = GETPOST('maskconstjob', 'alpha');
  82. $maskvalue = GETPOST('maskjob', 'alpha');
  83. if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
  84. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  85. }
  86. if (!($res > 0)) {
  87. $error++;
  88. }
  89. if (!$error) {
  90. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  91. } else {
  92. setEventMessages($langs->trans("Error"), null, 'errors');
  93. }
  94. } elseif ($action == 'specimen') {
  95. $modele = GETPOST('module', 'alpha');
  96. $tmpobjectkey = GETPOST('object');
  97. $tmpobject = new $tmpobjectkey($db);
  98. $tmpobject->initAsSpecimen();
  99. // Search template files
  100. $file = ''; $classname = ''; $filefound = 0;
  101. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  102. foreach ($dirmodels as $reldir) {
  103. $file = dol_buildpath($reldir."core/modules/recruitment/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  104. if (file_exists($file)) {
  105. $filefound = 1;
  106. $classname = "pdf_".$modele."_".strtolower($tmpobjectkey);
  107. break;
  108. }
  109. }
  110. if ($filefound) {
  111. require_once $file;
  112. $module = new $classname($db);
  113. if ($module->write_file($tmpobject, $langs) > 0) {
  114. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=recruitment-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  115. return;
  116. } else {
  117. setEventMessages($module->error, null, 'errors');
  118. dol_syslog($module->error, LOG_ERR);
  119. }
  120. } else {
  121. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  122. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  123. }
  124. } elseif ($action == 'set') {
  125. // Activate a model
  126. $ret = addDocumentModel($value, $type, $label, $scandir);
  127. } elseif ($action == 'del') {
  128. $ret = delDocumentModel($value, $type);
  129. if ($ret > 0) {
  130. $tmpobjectkey = GETPOST('object');
  131. if (!empty($tmpobjectkey)) {
  132. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  133. if ($conf->global->$constforval == "$value") {
  134. dolibarr_del_const($db, $constforval, $conf->entity);
  135. }
  136. }
  137. }
  138. } elseif ($action == 'setmod') {
  139. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  140. $tmpobjectkey = GETPOST('object');
  141. if (!empty($tmpobjectkey)) {
  142. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
  143. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  144. }
  145. } elseif ($action == 'setdoc') {
  146. // Set default model
  147. $tmpobjectkey = GETPOST('object');
  148. if (!empty($tmpobjectkey)) {
  149. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  150. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  151. // The constant that was read before the new set
  152. // We therefore requires a variable to have a coherent view
  153. $conf->global->$constforval = $value;
  154. }
  155. // We disable/enable the document template (into llx_document_model table)
  156. $ret = delDocumentModel($value, $type);
  157. if ($ret > 0) {
  158. $ret = addDocumentModel($value, $type, $label, $scandir);
  159. }
  160. }
  161. } elseif ($action == 'unsetdoc') {
  162. $tmpobjectkey = GETPOST('object');
  163. if (!empty($tmpobjectkey)) {
  164. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  165. dolibarr_del_const($db, $constforval, $conf->entity);
  166. }
  167. }
  168. /*
  169. * View
  170. */
  171. $form = new Form($db);
  172. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  173. $page_name = "RecruitmentSetup";
  174. llxHeader('', $langs->trans($page_name));
  175. // Subheader
  176. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  177. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  178. // Configuration header
  179. $head = recruitmentAdminPrepareHead();
  180. print dol_get_fiche_head($head, 'settings', '', -1, '');
  181. // Setup page goes here
  182. //echo '<span class="opacitymedium">'.$langs->trans("RecruitmentSetupPage").'</span><br><br>';
  183. if ($action == 'edit') {
  184. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  185. print '<input type="hidden" name="token" value="'.newToken().'">';
  186. print '<input type="hidden" name="action" value="update">';
  187. print '<table class="noborder centpercent">';
  188. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  189. foreach ($arrayofparameters as $key => $val) {
  190. print '<tr class="oddeven"><td>';
  191. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  192. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  193. print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
  194. }
  195. print '</table>';
  196. print '<br><div class="center">';
  197. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  198. print '</div>';
  199. print '</form>';
  200. print '<br>';
  201. } else {
  202. if (!empty($arrayofparameters)) {
  203. print '<table class="noborder centpercent">';
  204. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  205. foreach ($arrayofparameters as $key => $val) {
  206. $setupnotempty++;
  207. print '<tr class="oddeven"><td>';
  208. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  209. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  210. print '</td><td>'.getDolGlobalString($key).'</td></tr>';
  211. }
  212. print '</table>';
  213. print '<div class="tabsAction">';
  214. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  215. print '</div>';
  216. }
  217. }
  218. $moduledir = 'recruitment';
  219. $myTmpObjects = array();
  220. $myTmpObjects['RecruitmentJobPosition'] = array('includerefgeneration'=>1, 'includedocgeneration'=>1);
  221. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  222. if ($myTmpObjectArray['includerefgeneration']) {
  223. /*
  224. * Orders Numbering model
  225. */
  226. $setupnotempty++;
  227. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  228. print '<table class="noborder centpercent">';
  229. print '<tr class="liste_titre">';
  230. print '<td>'.$langs->trans("Name").'</td>';
  231. print '<td>'.$langs->trans("Description").'</td>';
  232. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  233. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  234. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  235. print '</tr>'."\n";
  236. clearstatcache();
  237. foreach ($dirmodels as $reldir) {
  238. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  239. if (is_dir($dir)) {
  240. $handle = opendir($dir);
  241. if (is_resource($handle)) {
  242. while (($file = readdir($handle)) !== false) {
  243. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  244. $file = substr($file, 0, dol_strlen($file) - 4);
  245. require_once $dir.'/'.$file.'.php';
  246. $module = new $file($db);
  247. // Show modules according to features level
  248. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  249. continue;
  250. }
  251. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  252. continue;
  253. }
  254. if ($module->isEnabled()) {
  255. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  256. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  257. print $module->info();
  258. print '</td>';
  259. // Show example of numbering model
  260. print '<td class="nowrap">';
  261. $tmp = $module->getExample();
  262. if (preg_match('/^Error/', $tmp)) {
  263. $langs->load("errors");
  264. print '<div class="error">'.$langs->trans($tmp).'</div>';
  265. } elseif ($tmp == 'NotConfigured') {
  266. print $langs->trans($tmp);
  267. } else {
  268. print $tmp;
  269. }
  270. print '</td>'."\n";
  271. print '<td class="center">';
  272. $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
  273. if (getDolGlobalString($constforvar) == $file) {
  274. print img_picto($langs->trans("Activated"), 'switch_on');
  275. } else {
  276. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  277. print img_picto($langs->trans("Disabled"), 'switch_off');
  278. print '</a>';
  279. }
  280. print '</td>';
  281. $mytmpinstance = new $myTmpObjectKey($db);
  282. $mytmpinstance->initAsSpecimen();
  283. // Info
  284. $htmltooltip = '';
  285. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  286. $nextval = $module->getNextValue($mytmpinstance);
  287. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  288. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  289. if ($nextval) {
  290. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  291. $nextval = $langs->trans($nextval);
  292. }
  293. $htmltooltip .= $nextval.'<br>';
  294. } else {
  295. $htmltooltip .= $langs->trans($module->error).'<br>';
  296. }
  297. }
  298. print '<td class="center">';
  299. print $form->textwithpicto('', $htmltooltip, 1, 0);
  300. print '</td>';
  301. print "</tr>\n";
  302. }
  303. }
  304. }
  305. closedir($handle);
  306. }
  307. }
  308. }
  309. print "</table><br>\n";
  310. }
  311. if ($myTmpObjectArray['includedocgeneration']) {
  312. /*
  313. * Document templates generators
  314. */
  315. $setupnotempty++;
  316. $type = strtolower($myTmpObjectKey);
  317. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  318. // Load array def with activated templates
  319. $def = array();
  320. $sql = "SELECT nom";
  321. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  322. $sql .= " WHERE type = '".$db->escape($type)."'";
  323. $sql .= " AND entity = ".$conf->entity;
  324. $resql = $db->query($sql);
  325. if ($resql) {
  326. $i = 0;
  327. $num_rows = $db->num_rows($resql);
  328. while ($i < $num_rows) {
  329. $array = $db->fetch_array($resql);
  330. array_push($def, $array[0]);
  331. $i++;
  332. }
  333. } else {
  334. dol_print_error($db);
  335. }
  336. print "<table class=\"noborder\" width=\"100%\">\n";
  337. print "<tr class=\"liste_titre\">\n";
  338. print '<td>'.$langs->trans("Name").'</td>';
  339. print '<td>'.$langs->trans("Description").'</td>';
  340. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  341. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  342. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  343. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  344. print "</tr>\n";
  345. clearstatcache();
  346. foreach ($dirmodels as $reldir) {
  347. foreach (array('', '/doc') as $valdir) {
  348. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  349. $dir = dol_buildpath($realpath);
  350. if (is_dir($dir)) {
  351. $handle = opendir($dir);
  352. if (is_resource($handle)) {
  353. while (($file = readdir($handle)) !== false) {
  354. $filelist[] = $file;
  355. }
  356. closedir($handle);
  357. arsort($filelist);
  358. foreach ($filelist as $file) {
  359. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  360. if (file_exists($dir.'/'.$file)) {
  361. $name = substr($file, 4, dol_strlen($file) - 16);
  362. $classname = substr($file, 0, dol_strlen($file) - 12);
  363. require_once $dir.'/'.$file;
  364. $module = new $classname($db);
  365. $modulequalified = 1;
  366. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  367. $modulequalified = 0;
  368. }
  369. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  370. $modulequalified = 0;
  371. }
  372. if ($modulequalified) {
  373. print '<tr class="oddeven"><td width="100">';
  374. print (empty($module->name) ? $name : $module->name);
  375. print "</td><td>\n";
  376. if (method_exists($module, 'info')) {
  377. print $module->info($langs);
  378. } else {
  379. print $module->description;
  380. }
  381. print '</td>';
  382. // Active
  383. if (in_array($name, $def)) {
  384. print '<td class="center">'."\n";
  385. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  386. print img_picto($langs->trans("Enabled"), 'switch_on');
  387. print '</a>';
  388. print '</td>';
  389. } else {
  390. print '<td class="center">'."\n";
  391. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  392. print "</td>";
  393. }
  394. // Default
  395. print '<td class="center">';
  396. $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON_PDF';
  397. if (getDolGlobalString($constforvar) == $name) {
  398. //print img_picto($langs->trans("Default"), 'on');
  399. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  400. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  401. } else {
  402. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  403. }
  404. print '</td>';
  405. // Info
  406. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  407. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  408. if ($module->type == 'pdf') {
  409. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  410. }
  411. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  412. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  413. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  414. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  415. print '<td class="center">';
  416. print $form->textwithpicto('', $htmltooltip, 1, 0);
  417. print '</td>';
  418. // Preview
  419. print '<td class="center">';
  420. if ($module->type == 'pdf') {
  421. $newname = preg_replace('/_'.preg_quote(strtolower($myTmpObjectKey), '/').'/', '', $name);
  422. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($newname).'&object='.urlencode($myTmpObjectKey).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  423. } else {
  424. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  425. }
  426. print '</td>';
  427. print "</tr>\n";
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. print '</table>';
  437. }
  438. }
  439. if (empty($setupnotempty)) {
  440. print '<br>'.$langs->trans("NothingToSetup");
  441. }
  442. // Page end
  443. print dol_get_fiche_end();
  444. llxFooter();
  445. $db->close();