settings.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. <?php // $Id: settings.php 20441 2009-05-10 07:39:15Z ivantcholakov $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University
  7. Copyright (c) Patrick Cool, Ghent University
  8. Copyright (c) Julio Montoya, Dokeos
  9. Copyright (c) Roan Embrechts, Vrije Universiteit Brussel
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  19. Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. * With this tool you can easily adjust non critical configuration settings.
  25. * Non critical means that changing them will not result in a broken campus.
  26. *
  27. * @author Patrick Cool
  28. * @since Dokeos 1.6
  29. * @author Julio Montoya - Multiple URL site
  30. * @package dokeos.admin
  31. ==============================================================================
  32. */
  33. /*
  34. ==============================================================================
  35. INIT SECTION
  36. ==============================================================================
  37. */
  38. // name of the language file that needs to be included
  39. $language_file = 'admin';
  40. // resetting the course id
  41. $cidReset=true;
  42. // including some necessary dokeos files
  43. include_once ('../inc/global.inc.php');
  44. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  45. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  46. require_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  47. // setting the section (for the tabs)
  48. $this_section = SECTION_PLATFORM_ADMIN;
  49. $_SESSION['this_section'] = $this_section;
  50. // Access restrictions
  51. api_protect_admin_script();
  52. // Submit Stylesheets
  53. if (isset($_POST['submit_stylesheets']))
  54. {
  55. $message = store_stylesheets();
  56. header("Location: ".api_get_self()."?category=stylesheets");
  57. exit;
  58. }
  59. // Database Table Definitions
  60. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  61. // setting breadcrumbs
  62. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  63. // setting the name of the tool
  64. $tool_name = get_lang('DokeosConfigSettings');
  65. // setting for templates
  66. $fck_attribute['ToolbarSet'] = "AdminTemplates";
  67. $fck_attribute['Width'] = '100%';
  68. $fck_attribute['Height'] = '400';
  69. // Build the form
  70. if (!empty($_GET['category']) and !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search')))
  71. {
  72. $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
  73. $renderer = & $form->defaultRenderer();
  74. $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
  75. $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
  76. $my_category = mysql_real_escape_string($_GET['category']);
  77. $sqlcountsettings = "SELECT COUNT(*) FROM $table_settings_current WHERE category='".$my_category."' AND type<>'checkbox'";
  78. $resultcountsettings = api_sql_query($sqlcountsettings, __FILE__, __LINE__);
  79. $countsetting = mysql_fetch_array($resultcountsettings);
  80. if ($_configuration['access_url']==1)
  81. {
  82. $settings = api_get_settings($my_category,'group',$_configuration['access_url']);
  83. }
  84. else
  85. {
  86. $url_info = api_get_access_url($_configuration['access_url']);
  87. if ($url_info['active']==1)
  88. {
  89. //the default settings of Dokeos
  90. $settings = api_get_settings($my_category,'group',1,0);
  91. //the settings that are changeable from a particular site
  92. $settings_by_access = api_get_settings($my_category,'group',$_configuration['access_url'],1);
  93. //echo '<pre>';
  94. //print_r($settings_by_access);
  95. $settings_by_access_list=array();
  96. foreach($settings_by_access as $row)
  97. {
  98. if (empty($row['variable']))
  99. $row['variable']=0;
  100. if (empty($row['subkey']))
  101. $row['subkey']=0;
  102. if (empty($row['category']))
  103. $row['category']=0;
  104. // one more validation if is changeable
  105. if ($row['access_url_changeable']==1)
  106. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  107. else
  108. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  109. }
  110. }
  111. }
  112. //print_r($settings_by_access_list);echo '</pre>';
  113. //$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
  114. //$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__);
  115. //while ($row = mysql_fetch_array($resultsettings))
  116. $default_values = array();
  117. foreach($settings as $row) {
  118. ($countsetting['0']%10) < 5 ?$b=$countsetting['0']-10:$b=$countsetting['0'];
  119. if ($i % 10 == 0 and $i<$b){
  120. if ($_GET['category'] <> "Languages"){
  121. $form->addElement('html','<div align="right">');
  122. $form->addElement('style_submit_button', null,get_lang('SaveSettings'), 'class="save"');
  123. $form->addElement('html','</div>');
  124. }
  125. }
  126. $i++;
  127. $form->addElement('header', null, get_lang($row['title']));
  128. if ($row['access_url_changeable']=='1' && $_configuration['multiple_access_urls']==true) {
  129. $form->addElement('html', '<div style="float:right;">'.Display::return_icon('shared_setting.png',get_lang('SharedSettingIconComment')).'</div>');
  130. }
  131. $hideme=array();
  132. $hide_element=false;
  133. if ($_configuration['access_url']!=1)
  134. {
  135. if ($row['access_url_changeable']==0)
  136. {
  137. //we hide the element in other cases (checkbox, radiobutton) we 'freeze' the element
  138. $hide_element=true;
  139. $hideme=array('disabled');
  140. }
  141. elseif($url_info['active']==1)
  142. {
  143. // we show the elements
  144. if (empty($row['variable']))
  145. $row['variable']=0;
  146. if (empty($row['subkey']))
  147. $row['subkey']=0;
  148. if (empty($row['category']))
  149. $row['category']=0;
  150. if (is_array ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]))
  151. {
  152. // we are sure that the other site have a selected value
  153. if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value']!='')
  154. $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value'];
  155. }
  156. // there is no else because we load the default $row['selected_value'] of the main Dokeos site
  157. }
  158. }
  159. switch ($row['type']) {
  160. case 'textfield' :
  161. if ($row['variable']=='account_valid_duration') {
  162. $form->addElement('text', $row['variable'], get_lang($row['comment']),array('maxlength'=>'5'));
  163. $form->applyFilter($row['variable'],'html_filter');
  164. $default_values[$row['variable']] = $row['selected_value'];
  165. } else {
  166. $form->addElement('text', $row['variable'], get_lang($row['comment']),$hideme);
  167. $form->applyFilter($row['variable'],'html_filter');
  168. $default_values[$row['variable']] = $row['selected_value'];
  169. }
  170. break;
  171. case 'textarea' :
  172. $form->addElement('textarea', $row['variable'], get_lang($row['comment']),$hideme);
  173. $default_values[$row['variable']] = $row['selected_value'];
  174. break;
  175. case 'radio' :
  176. $values = get_settings_options($row['variable']);
  177. $group = array ();
  178. if (is_array($values )) {
  179. foreach ($values as $key => $value) {
  180. $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
  181. if ($hide_element) {
  182. $element->freeze();
  183. }
  184. $group[] = $element;
  185. }
  186. }
  187. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />', false);
  188. $default_values[$row['variable']] = $row['selected_value'];
  189. break;
  190. case 'checkbox';
  191. //1. we collect all the options of this variable
  192. $sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = 1";
  193. $result = api_sql_query($sql, __FILE__, __LINE__);
  194. $group = array ();
  195. while ($rowkeys = Database::fetch_array($result)) {
  196. $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
  197. if ($row['access_url_changeable']==1) {
  198. //2. we look into the DB if there is a setting for a specific access_url
  199. $access_url = $_configuration['access_url'];
  200. if(empty($access_url )) $access_url =1;
  201. $sql = "SELECT selected_value FROM settings_current WHERE variable='".$rowkeys['variable']."' AND subkey='".$rowkeys['subkey']."' AND subkeytext='".$rowkeys['subkeytext']."' AND access_url = $access_url";
  202. $result_access = api_sql_query($sql, __FILE__, __LINE__);
  203. $row_access = Database::fetch_array($result_access);
  204. if ($row_access['selected_value'] == 'true' && ! $form->isSubmitted()) {
  205. $element->setChecked(true);
  206. }
  207. } else {
  208. if ($rowkeys['selected_value'] == 'true' && ! $form->isSubmitted()) {
  209. $element->setChecked(true);
  210. }
  211. }
  212. if ($hide_element) {
  213. $element->freeze();
  214. }
  215. $group[] = $element;
  216. }
  217. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />'."\n");
  218. break;
  219. case "link" :
  220. $form->addElement('static', null, get_lang($row['comment']), get_lang('CurrentValue').' : '.$row['selected_value'],$hideme);
  221. }
  222. }
  223. if ($_GET['category'] <> "Languages"){
  224. $form->addElement('html','<div align="right">');
  225. $form->addElement('style_submit_button', null,get_lang('SaveSettings'), 'class="save"');
  226. $form->addElement('html','</div>');
  227. }
  228. $form->setDefaults($default_values);
  229. if ($form->validate())
  230. {
  231. $values = $form->exportValues();
  232. // the first step is to set all the variables that have type=checkbox of the category
  233. // to false as the checkbox that is unchecked is not in the $_POST data and can
  234. // therefore not be set to false.
  235. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  236. // will be set to false.
  237. $r = api_set_settings_category($my_category,'false',$_configuration['access_url']);
  238. //$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'";
  239. //$result = api_sql_query($sql, __FILE__, __LINE__);
  240. // Save the settings
  241. foreach ($values as $key => $value)
  242. {
  243. if (!is_array($value))
  244. {
  245. //$sql = "UPDATE $table_settings_current SET selected_value='".mysql_real_escape_string($value)."' WHERE variable='$key'";
  246. //$result = api_sql_query($sql, __FILE__, __LINE__);
  247. $result = api_set_setting($key,$value,null,null,$_configuration['access_url']);
  248. }
  249. else
  250. {
  251. foreach ($value as $subkey => $subvalue)
  252. {
  253. //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'";
  254. //$result = api_sql_query($sql, __FILE__, __LINE__);
  255. $result = api_set_setting($key,'true',$subkey,null,$_configuration['access_url']);
  256. }
  257. }
  258. }
  259. header('Location: settings.php?action=stored&category='.$_GET['category']);
  260. exit;
  261. }
  262. }
  263. // including the header (banner)
  264. Display :: display_header($tool_name);
  265. //api_display_tool_title($tool_name);
  266. // displaying the message that the settings have been stored
  267. if (!empty($_GET['action']) && $_GET['action'] == "stored")
  268. {
  269. Display :: display_normal_message($SettingsStored);
  270. }
  271. // the action images
  272. $action_images['platform'] = 'dokeos.gif';
  273. $action_images['course'] = 'course.gif';
  274. $action_images['tools'] = 'reference.gif';
  275. $action_images['user'] = 'students.gif';
  276. $action_images['gradebook'] = 'gradebook_eval_not_empty.gif';
  277. $action_images['ldap'] = 'loginmanager.gif';
  278. $action_images['security'] = 'passwordprotected.gif';
  279. $action_images['languages'] = 'forum.gif';
  280. $action_images['tuning'] = 'tuning.gif';
  281. $action_images['plugins'] = 'plugin.gif';
  282. $action_images['stylesheets'] = 'theme.gif';
  283. $action_images['templates'] = 'template.gif';
  284. $action_images['search'] = 'search.gif';
  285. // grabbing the categories
  286. //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
  287. //$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__);
  288. $resultcategories = api_get_settings_categories(array('stylesheets','Plugins', 'Templates', 'Search'));
  289. echo "\n<div class=\"actions\">";
  290. //while ($row = mysql_fetch_array($resultcategories))
  291. foreach($resultcategories as $row)
  292. {
  293. echo "\n\t<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category']))).api_ucfirst(get_lang($row['category']))."</a>";
  294. }
  295. echo "\n\t<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], api_ucfirst(get_lang('Plugins'))).api_ucfirst(get_lang('Plugins'))."</a>";
  296. echo "\n\t<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], api_ucfirst(get_lang('Stylesheets'))).api_ucfirst(get_lang('Stylesheets'))."</a>";
  297. echo "\n\t<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], api_ucfirst(get_lang('Templates'))).api_ucfirst(get_lang('Templates'))."</a>";
  298. echo "\n\t<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], api_ucfirst(get_lang('Search'))).api_ucfirst(get_lang('Search'))."</a>";
  299. echo "\n</div>";
  300. if (isset ($_GET['category']))
  301. {
  302. switch ($_GET['category'])
  303. {
  304. // displaying the extensions: plugins
  305. // this will be available to all the sites (access_urls)
  306. case 'Plugins' :
  307. handle_plugins();
  308. break;
  309. // displaying the extensions: Stylesheets
  310. case 'stylesheets' :
  311. handle_stylesheets();
  312. break;
  313. case 'Search' :
  314. handle_search();
  315. break;
  316. case 'Templates' :
  317. handle_templates();
  318. break;
  319. default :
  320. $form->display();
  321. }
  322. }
  323. /*
  324. ==============================================================================
  325. FOOTER
  326. ==============================================================================
  327. */
  328. Display :: display_footer();
  329. /*
  330. ==============================================================================
  331. FUNCTIONS
  332. ==============================================================================
  333. */
  334. /**
  335. * The function that retrieves all the possible settings for a certain config setting
  336. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  337. */
  338. function get_settings_options($var)
  339. {
  340. $table_settings_options = Database :: get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  341. $sql = "SELECT * FROM $table_settings_options WHERE variable='$var'";
  342. $result = api_sql_query($sql, __FILE__, __LINE__);
  343. while ($row = mysql_fetch_array($result))
  344. {
  345. $temp_array = array ('value' => $row['value'], 'display_text' => $row['display_text']);
  346. $settings_options_array[] = $temp_array;
  347. }
  348. return $settings_options_array;
  349. }
  350. /**
  351. * This function allows easy activating and inactivating of plugins
  352. * @todo: a similar function needs to be written to activate or inactivate additional tools.
  353. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  354. */
  355. function handle_plugins()
  356. {
  357. global $SettingsStored;
  358. $userplugins = array();
  359. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  360. if (isset($_POST['submit_plugins']))
  361. {
  362. store_plugins();
  363. Display :: display_normal_message($SettingsStored);
  364. }
  365. echo get_lang('AvailablePlugins')."<br/><br/>";
  366. /* We scan the plugin directory. Each folder is a potential plugin. */
  367. $pluginpath = api_get_path(SYS_PLUGIN_PATH);
  368. $handle = @opendir($pluginpath);
  369. while (false !== ($file = readdir($handle)))
  370. {
  371. if ($file <> '.' AND $file <> '..' AND is_dir(api_get_path(SYS_PLUGIN_PATH).$file))
  372. {
  373. $possibleplugins[] = $file;
  374. }
  375. }
  376. @closedir($handle);
  377. /* for each of the possible plugin dirs we check if a file plugin.php (that contains all the needed information about this plugin)
  378. can be found in the dir.
  379. this plugin.php file looks like
  380. $plugin_info['title']='The title of the plugin'; //
  381. $plugin_info['comment']="Some comment about the plugin";
  382. $plugin_info['location']=array("loginpage_menu", "campushomepage_menu","banner"); // the possible locations where the plugins can be used
  383. $plugin_info['version']='0.1 alpha'; // The version number of the plugin
  384. $plugin_info['author']='Patrick Cool'; // The author of the plugin
  385. */
  386. echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.$_GET['category'].'">';
  387. echo "<table class=\"data_table\">\n";
  388. echo "\t<tr>\n";
  389. echo "\t\t<th>\n";
  390. echo get_lang('Plugin');
  391. echo "\t\t</th>\n";
  392. echo "\t\t<th>\n";
  393. echo get_lang('LoginPageMainArea');
  394. echo "\t\t</th>\n";
  395. echo "\t\t<th>\n";
  396. echo get_lang('LoginPageMenu');
  397. echo "\t\t</th>\n";
  398. echo "\t\t<th>\n";
  399. echo get_lang('CampusHomepageMainArea');
  400. echo "\t\t</th>\n";
  401. echo "\t\t<th>\n";
  402. echo get_lang('CampusHomepageMenu');
  403. echo "\t\t</th>\n";
  404. echo "\t\t<th>\n";
  405. echo get_lang('MyCoursesMainArea');
  406. echo "\t\t</th>\n";
  407. echo "\t\t<th>\n";
  408. echo get_lang('MyCoursesMenu');
  409. echo "\t\t</th>\n";
  410. echo "\t\t<th>\n";
  411. echo get_lang('Header');
  412. echo "\t\t</th>\n";
  413. echo "\t\t<th>\n";
  414. echo get_lang('Footer');
  415. echo "\t\t</th>\n";
  416. echo "\t</tr>\n";
  417. /* We retrieve all the active plugins. */
  418. //$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'";
  419. //$result = api_sql_query($sql);
  420. $result = api_get_settings('Plugins');
  421. //while ($row = mysql_fetch_array($result))
  422. foreach($result as $row)
  423. {
  424. $usedplugins[$row['variable']][] = $row['selected_value'];
  425. }
  426. /* We display all the possible plugins and the checkboxes */
  427. foreach ($possibleplugins as $testplugin)
  428. {
  429. $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$testplugin."/plugin.php";
  430. if (file_exists($plugin_info_file))
  431. {
  432. $plugin_info = array();
  433. include ($plugin_info_file);
  434. echo "\t<tr>\n";
  435. echo "\t\t<td>\n";
  436. foreach ($plugin_info as $key => $value)
  437. {
  438. if ($key <> 'location')
  439. {
  440. if ($key == 'title')
  441. {
  442. $value = '<strong>'.$value.'</strong>';
  443. }
  444. echo get_lang(ucwords($key)).': '.$value.'<br />';
  445. }
  446. }
  447. if (file_exists(api_get_path(SYS_PLUGIN_PATH).$testplugin.'/readme.txt'))
  448. {
  449. echo "<a href='".api_get_path(WEB_PLUGIN_PATH).$testplugin."/readme.txt'>readme.txt</a>";
  450. }
  451. echo "\t\t</td>\n";
  452. // column: LoginPageMainArea
  453. if(empty($usedplugins))
  454. {
  455. $usedplugins = array();
  456. }
  457. display_plugin_cell('loginpage_main', $plugin_info, $testplugin, $usedplugins);
  458. display_plugin_cell('loginpage_menu', $plugin_info, $testplugin, $usedplugins);
  459. display_plugin_cell('campushomepage_main', $plugin_info, $testplugin, $usedplugins);
  460. display_plugin_cell('campushomepage_menu', $plugin_info, $testplugin, $usedplugins);
  461. display_plugin_cell('mycourses_main', $plugin_info, $testplugin, $usedplugins);
  462. display_plugin_cell('mycourses_menu', $plugin_info, $testplugin, $usedplugins);
  463. display_plugin_cell('header', $plugin_info, $testplugin, $usedplugins);
  464. display_plugin_cell('footer', $plugin_info, $testplugin, $usedplugins);
  465. echo "\t</tr>\n";
  466. }
  467. }
  468. echo '</table>';
  469. echo '<button class="save" type="submit" name="submit_plugins">'.get_lang('EnablePlugins').'</button></form>';
  470. }
  471. function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins)
  472. {
  473. echo "\t\t<td align=\"center\">\n";
  474. if (in_array($location, $plugin_info['location']))
  475. {
  476. if (isset($active_plugins[$location]) && is_array($active_plugins[$location])
  477. && in_array($current_plugin, $active_plugins[$location]))
  478. {
  479. $checked = "checked";
  480. }
  481. else
  482. {
  483. $checked = '';
  484. }
  485. echo '<input type="checkbox" name="'.$current_plugin.'-'.$location.'" value="true" '.$checked.'/>';
  486. }
  487. echo "\t\t</td>\n";
  488. }
  489. /**
  490. * This function allows the platform admin to choose the default stylesheet
  491. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  492. */
  493. function handle_stylesheets()
  494. {
  495. global $_configuration;
  496. // Current style
  497. $currentstyle = api_get_setting('stylesheets');
  498. $is_style_changeable=false;
  499. if ($_configuration['access_url']!=1)
  500. {
  501. $style_info = api_get_settings('stylesheets','',1,0);
  502. $url_info = api_get_access_url($_configuration['access_url']);
  503. if ($style_info[0]['access_url_changeable']==1 && $url_info['active']==1)
  504. {
  505. $is_style_changeable=true;
  506. echo '<div class="actions" id="stylesheetuploadlink">';
  507. Display::display_icon('theme_add.gif');
  508. echo '<a href="" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">'.get_lang('UploadNewStylesheet').'</a>';
  509. echo '</div>';
  510. }
  511. }
  512. else
  513. {
  514. $is_style_changeable=true;
  515. echo '<div class="actions" id="stylesheetuploadlink">';
  516. Display::display_icon('theme_add.gif');
  517. echo '<a href="" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">'.get_lang('UploadNewStylesheet').'</a>';
  518. echo '</div>';
  519. }
  520. $form = new FormValidator('stylesheet_upload','post','settings.php?category=stylesheets&showuploadform=true');
  521. $form->addElement('text','name_stylesheet',get_lang('NameStylesheet'),array('size' => '40', 'maxlength' => '40'));
  522. $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
  523. $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
  524. $allowed_file_types = array ('css');
  525. $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types);
  526. $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
  527. $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Ok'), array('class'=>'save'));
  528. if( $form->validate() AND is_writable(api_get_path(SYS_CODE_PATH).'css/'))
  529. {
  530. $values = $form->exportValues();
  531. $picture_element = & $form->getElement('new_stylesheet');
  532. $picture = $picture_element->getValue();
  533. upload_stylesheet($values, $picture);
  534. Display::display_confirmation_message(get_lang('StylesheetAdded'));
  535. }
  536. else
  537. {
  538. if (!is_writable(api_get_path(SYS_CODE_PATH).'css/'))
  539. {
  540. Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable'));
  541. }
  542. else
  543. {
  544. if ($_GET['showuploadform'] == 'true')
  545. {
  546. echo '<div id="newstylesheetform">';
  547. }
  548. else
  549. {
  550. echo '<div id="newstylesheetform" style="display: none;">';
  551. }
  552. // uploading a new stylesheet
  553. if ($_configuration['access_url']==1)
  554. {
  555. $form->display();
  556. }
  557. else
  558. {
  559. if ($is_style_changeable)
  560. {
  561. $form->display();
  562. }
  563. }
  564. echo '</div>';
  565. }
  566. }
  567. // Preview of the stylesheet
  568. echo '<div><iframe src="style_preview.php" width="100%" height="300" name="preview"></iframe></div>';
  569. echo '<form name="stylesheets" method="post" action="'.api_get_self().'?category='.$_GET['category'].'">';
  570. if ($handle = @opendir(api_get_path(SYS_PATH).'main/css/'))
  571. {
  572. $counter=1;
  573. while (false !== ($style_dir = readdir($handle)))
  574. {
  575. if(substr($style_dir,0,1)=='.') //skip dirs starting with a '.'
  576. {
  577. continue;
  578. }
  579. $dirpath = api_get_path(SYS_PATH).'main/css/'.$style_dir;
  580. if (is_dir($dirpath))
  581. {
  582. if ($style_dir != '.' && $style_dir != '..')
  583. {
  584. if ($currentstyle == $style_dir OR ($style_dir == 'dokeos_classic' AND !$currentstyle))
  585. {
  586. $selected = 'checked="checked"';
  587. }
  588. else
  589. {
  590. $selected = '';
  591. }
  592. $show_name=get_lang($style_dir, '');
  593. if ($is_style_changeable)
  594. {
  595. echo "<input type=\"radio\" name=\"style\" value=\"".$style_dir."\" ".$selected." onClick=\"parent.preview.location='style_preview.php?style=".$style_dir."';\"/>";
  596. echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
  597. }
  598. else
  599. echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
  600. //echo '<div id="Layer'.$counter.'" style="position:relative; width:687px; z-index:2; visibility: hidden;">';
  601. //echo '<a href="#" onClick="MM_showHideLayers(\'Layer'.$counter.'\',\'\',\'hide\')">'.get_lang('Close').'</a>';
  602. //echo '<iframe src="style_preview.php?style='.$file.'" width="100%" style="float:right;"></iframe></div>';
  603. echo "<br />\n";
  604. $counter++;
  605. }
  606. }
  607. }
  608. @closedir($handle);
  609. }
  610. if ($is_style_changeable)
  611. {
  612. echo '<button class="save" type="submit" name="submit_stylesheets"> '.get_lang('SaveSettings').' </button></form>';
  613. }
  614. }
  615. /**
  616. * creates the folder (if needed) and uploads the stylesheet in it
  617. *
  618. * @param array $values the values of the form
  619. * @param array $picture the values of the uploaded file
  620. *
  621. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  622. * @version May 2008
  623. * @since Dokeos 1.8.5
  624. */
  625. function upload_stylesheet($values,$picture)
  626. {
  627. // valid name for the stylesheet folder
  628. $style_name = api_ereg_replace("[^A-Za-z0-9]", "", $values['name_stylesheet'] );
  629. // create the folder if needed
  630. if(!is_dir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'))
  631. {
  632. if(mkdir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'))
  633. {
  634. $perm = api_get_setting('permissions_for_new_directories');
  635. $perm = octdec(!empty($perm)?$perm:'0770');
  636. chmod(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/', $perm);
  637. }
  638. }
  639. // move the file in the folder
  640. move_uploaded_file($picture['tmp_name'], api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'.$picture['name']);
  641. }
  642. /**
  643. * This function allows easy activating and inactivating of plugins
  644. * @todo: a similar function needs to be written to activate or inactivate additional tools.
  645. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  646. */
  647. function store_plugins()
  648. {
  649. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  650. global $_configuration;
  651. // Step 1 : we remove all the plugins
  652. //$sql = "DELETE FROM $table_settings_current WHERE category='Plugins'";
  653. //api_sql_query($sql, __LINE__, __FILE__);
  654. $r = api_delete_category_settings('Plugins',$_configuration['access_url']);
  655. // step 2: looping through all the post values we only store these which are really a valid plugin location.
  656. foreach ($_POST as $form_name => $formvalue)
  657. {
  658. $form_name_elements = explode("-", $form_name);
  659. if (is_valid_plugin_location($form_name_elements[1]))
  660. {
  661. //$sql = "INSERT into $table_settings_current (variable,category,selected_value) VALUES ('".$form_name_elements['1']."','Plugins','".$form_name_elements['0']."')";
  662. //api_sql_query($sql, __LINE__, __FILE__);
  663. api_add_setting($form_name_elements['0'],$form_name_elements['1'],$form_name_elements['0'],null,'Plugins',$form_name_elements['0'],null,null,null,$_configuration['access_url'],1);
  664. }
  665. }
  666. }
  667. /**
  668. * Check if the post information is really a valid plugin location.
  669. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  670. */
  671. function is_valid_plugin_location($location)
  672. {
  673. $valid_locations=array('loginpage_main', 'loginpage_menu', 'campushomepage_main', 'campushomepage_menu', 'mycourses_main', 'mycourses_menu','header', 'footer');
  674. if (in_array($location, $valid_locations))
  675. {
  676. return true;
  677. }
  678. else
  679. {
  680. return false;
  681. }
  682. }
  683. /**
  684. * This function allows the platform admin to choose which should be the default stylesheet
  685. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  686. */
  687. function store_stylesheets()
  688. {
  689. global $_configuration;
  690. // Database Table Definitions
  691. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  692. // Insert the stylesheet
  693. $style = Database::escape_string($_POST['style']);
  694. if (is_style($style))
  695. {
  696. /*
  697. $sql = 'UPDATE '.$table_settings_current.' SET
  698. selected_value = "'.$style.'"
  699. WHERE variable = "stylesheets"
  700. AND category = "stylesheets"';
  701. api_sql_query($sql, __LINE__, __FILE__);
  702. */
  703. api_set_setting('stylesheets',$style,null,'stylesheets',$_configuration['access_url']);
  704. }
  705. return true;
  706. }
  707. /**
  708. * This function checks if the given style is a recognize style that exists in the css directory as
  709. * a standalone directory.
  710. * @param string Style
  711. * @return bool True if this style is recognized, false otherwise
  712. */
  713. function is_style($style)
  714. {
  715. $dir = api_get_path(SYS_PATH).'main/css/';
  716. $dirs = scandir($dir);
  717. $style = str_replace(array('/','\\'),array('',''),$style); //avoid slashes or backslashes
  718. if (in_array($style,$dirs) && is_dir($dir.$style))
  719. {
  720. return true;
  721. }
  722. return false;
  723. }
  724. /**
  725. * Search options
  726. * TODO: support for multiple site. aka $_configuration['access_url'] == 1
  727. * @author Marco Villegas <marvil07@gmail.com>
  728. */
  729. function handle_search() {
  730. global $SettingsStored, $_configuration;
  731. $search_enabled = api_get_setting('search_enabled');
  732. $settings = api_get_settings('Search');
  733. if ($search_enabled !== 'true' || count($settings) < 1) {
  734. Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
  735. return;
  736. }
  737. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  738. $form = new FormValidator('search-options', 'post', api_get_self().'?category=Search');
  739. $renderer = & $form->defaultRenderer();
  740. $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
  741. $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
  742. //search_show_unlinked_results
  743. $form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
  744. $form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment'));
  745. $values = get_settings_options('search_show_unlinked_results');
  746. $group = array ();
  747. foreach ($values as $key => $value) {
  748. $element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
  749. $group[] = $element;
  750. }
  751. $form->addGroup($group, 'search_show_unlinked_results', get_lang('SearchShowUnlinkedResultsComment'), '<br />', false);
  752. $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
  753. //search_prefilter_prefix
  754. $form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
  755. $form->addElement('label', null, get_lang('SearchPrefilterPrefixComment'));
  756. $specific_fields = get_specific_field_list();
  757. $sf_values = array();
  758. foreach ($specific_fields as $sf) {
  759. $sf_values[$sf['code']] = $sf['name'];
  760. }
  761. $group = array ();
  762. $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
  763. $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
  764. //$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required');
  765. $form->addElement('style_submit_button', 'search-options-save', get_lang('Ok'));
  766. $form->setDefaults($default_values);
  767. if( $form->validate()) {
  768. $formvalues = $form->exportValues();
  769. $r = api_set_settings_category('Search','false',$_configuration['access_url']);
  770. // Save the settings
  771. foreach ($formvalues as $key => $value)
  772. {
  773. $result = api_set_setting($key,$value,null,null);
  774. }
  775. Display :: display_normal_message($SettingsStored);
  776. } else {
  777. echo '<div id="search-options-form">';
  778. $form->display();
  779. echo '</div>';
  780. }
  781. }
  782. /**
  783. * wrapper for the templates
  784. *
  785. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  786. * @version August 2008
  787. * @since Dokeos 1.8.6
  788. */
  789. function handle_templates()
  790. {
  791. if ($_GET['action'] != 'add') {
  792. echo "\n<div class=\"actions\" style=\"margin-left:1px\" >";
  793. echo '<a href="settings.php?category=Templates&amp;action=add">'.Display::return_icon('template_add.gif', get_lang('AddTemplate')).get_lang('AddTemplate').'</a>';
  794. echo "\n</div>";
  795. }
  796. if ($_GET['action'] == 'add' OR ( $_GET['action'] == 'edit' AND is_numeric($_GET['id']))) {
  797. add_edit_template();
  798. } else {
  799. if ($_GET['action'] == 'delete' and is_numeric($_GET['id'])) {
  800. delete_template($_GET['id']);
  801. }
  802. display_templates();
  803. }
  804. }
  805. /**
  806. * Display a sortable table with all the templates that the platform administrator has defined.
  807. *
  808. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  809. * @version August 2008
  810. * @since Dokeos 1.8.6
  811. */
  812. function display_templates()
  813. {
  814. $table = new SortableTable('templates', 'get_number_of_templates', 'get_template_data',1);
  815. $table->set_additional_parameters(array('category'=>$_GET['category']));
  816. $table->set_header(0, get_lang('Image'), true, array ('style' => 'width:101px;'));
  817. $table->set_header(1, get_lang('Title'));
  818. $table->set_header(2, get_lang('Actions'), false, array ('style' => 'width:30px;'));
  819. $table->set_column_filter(2,'actions_filter');
  820. $table->set_column_filter(0,'image_filter');
  821. $table->display();
  822. }
  823. /**
  824. * Get the number of templates that are defined by the platform admin.
  825. *
  826. * @return integer
  827. *
  828. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  829. * @version August 2008
  830. * @since Dokeos 1.8.6
  831. */
  832. function get_number_of_templates()
  833. {
  834. // Database table definition
  835. $table_system_template = Database :: get_main_table('system_template');
  836. // The sql statement
  837. $sql = "SELECT COUNT(id) AS total FROM $table_system_template";
  838. $result = api_sql_query($sql, __FILE__, __LINE__);
  839. $row = Database::fetch_array($result);
  840. // returning the number of templates
  841. return $row['total'];
  842. }
  843. /**
  844. * Get all the template data for the sortable table
  845. *
  846. * @param integer $from the start of the limit statement
  847. * @param integer $number_of_items the number of elements that have to be retrieved from the database
  848. * @param integer $column the column that is
  849. * @param string $direction the sorting direction (ASC or DESC�
  850. * @return array
  851. *
  852. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  853. * @version August 2008
  854. * @since Dokeos 1.8.6
  855. */
  856. function get_template_data($from, $number_of_items, $column, $direction)
  857. {
  858. // Database table definition
  859. $table_system_template = Database :: get_main_table('system_template');
  860. // the sql statement
  861. $sql = "SELECT image as col0, title as col1, id as col2 FROM $table_system_template";
  862. $sql .= " ORDER BY col$column $direction ";
  863. $sql .= " LIMIT $from,$number_of_items";
  864. $result = api_sql_query($sql, __FILE__, __LINE__);
  865. while ($row = Database::fetch_array($result))
  866. {
  867. $return[]=$row;
  868. }
  869. // returning all the information for the sortable table
  870. return $return;
  871. }
  872. /**
  873. * display the edit and delete icons in the sortable table
  874. *
  875. * @param integer $id the id of the template
  876. * @return html code for the link to edit and delete the template
  877. *
  878. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  879. * @version August 2008
  880. * @since Dokeos 1.8.6
  881. */
  882. function actions_filter($id)
  883. {
  884. $return .= '<a href="settings.php?category=Templates&amp;action=edit&amp;id='.Security::remove_XSS($id).'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  885. $return .= '<a href="settings.php?category=Templates&amp;action=delete&amp;id='.Security::remove_XSS($id).'" onclick="javascript:if(!confirm('."'".get_lang("ConfirmYourChoice")."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  886. return $return;
  887. }
  888. /**
  889. * Display the image of the template in the sortable table
  890. *
  891. * @param string $image the image
  892. * @return html code for the image
  893. *
  894. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  895. * @version August 2008
  896. * @since Dokeos 1.8.6
  897. */
  898. function image_filter($image)
  899. {
  900. if (!empty($image))
  901. {
  902. return '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/'.$image.'" alt="'.get_lang('TemplatePreview').'"/>';
  903. }
  904. else
  905. {
  906. return '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>';
  907. }
  908. }
  909. /**
  910. * Add (or edit) a template. This function displays the form and also takes care of uploading the image and storing the information in the database
  911. *
  912. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  913. * @version August 2008
  914. * @since Dokeos 1.8.6
  915. */
  916. function add_edit_template()
  917. {
  918. // initiate the object
  919. $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.$_GET['action'].'&id='.$_GET['id']);
  920. // settting the form elements: the header
  921. if ($_GET['action'] == 'add')
  922. {
  923. $title = get_lang('AddTemplate');
  924. }
  925. else
  926. {
  927. $title = get_lang('EditTemplate');
  928. }
  929. $form->addElement('header', '', $title);
  930. // settting the form elements: the title of the template
  931. $form->add_textfield('title', get_lang('Title'), false);
  932. // settting the form elements: the content of the template (wysiwyg editor)
  933. $form->addElement('html_editor', 'template_text', get_lang('Text'));
  934. // settting the form elements: the form to upload an image to be used with the template
  935. $form->addElement('file','template_image',get_lang('Image'),'');
  936. // settting the form elements: a little bit information about the template image
  937. $form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
  938. // getting all the information of the template when editing a template
  939. if ($_GET['action'] == 'edit')
  940. {
  941. // Database table definition
  942. $table_system_template = Database :: get_main_table('system_template');
  943. $sql = "SELECT * FROM $table_system_template WHERE id = '".Database::escape_string($_GET['id'])."'";
  944. $result = api_sql_query($sql, __FILE__, __LINE__);
  945. $row = Database::fetch_array($result);
  946. $defaults['template_id'] = $_GET['id'];
  947. $defaults['template_text'] = $row['content'];
  948. $defaults['title'] = $row['title'];
  949. // adding an extra field: a hidden field with the id of the template we are editing
  950. $form->addElement('hidden','template_id');
  951. // adding an extrra field: a preview of the image that is currently used
  952. if (!empty($row['image']))
  953. {
  954. $form->addElement('static','template_image_preview', '', '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/'.$row['image'].'" alt="'.get_lang('TemplatePreview').'"/>');
  955. }
  956. else
  957. {
  958. $form->addElement('static','template_image_preview', '', '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>');
  959. }
  960. // setting the information of the template that we are editing
  961. $form->setDefaults($defaults);
  962. }
  963. // settting the form elements: the submit button
  964. $form->addElement('style_submit_button' , 'submit', get_lang('Ok') ,'class="save"');
  965. // setting the rules: the required fields
  966. $form->addRule('title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  967. $form->addRule('template_text', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  968. // if the form validates (complies to all rules) we save the information, else we display the form again (with error message if needed)
  969. if( $form->validate() )
  970. {
  971. // exporting the values
  972. $values = $form->exportValues();
  973. // upload the file
  974. if (!empty($_FILES['template_image']['name']))
  975. {
  976. include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  977. $upload_ok = process_uploaded_file($_FILES['template_image']);
  978. if ($upload_ok)
  979. {
  980. // Try to add an extension to the file if it hasn't one
  981. $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
  982. // upload dir
  983. $upload_dir = api_get_path(SYS_PATH).'home/default_platform_document/';
  984. // create dir if not exists
  985. if (!is_dir($upload_dir)) {
  986. $perm = api_get_setting('permissions_for_new_directories');
  987. $perm = octdec(!empty($perm)?$perm:'0770');
  988. $res = @mkdir($upload_dir,$perm);
  989. }
  990. // resize image to max default and upload
  991. require_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  992. $temp = new image($_FILES['template_image']['tmp_name']);
  993. $picture_infos=@getimagesize($_FILES['template_image']['tmp_name']);
  994. $max_width_for_picture = 100;
  995. if ($picture_infos[0]>$max_width_for_picture)
  996. {
  997. $thumbwidth = $max_width_for_picture;
  998. if (empty($thumbwidth) or $thumbwidth==0) {
  999. $thumbwidth=$max_width_for_picture;
  1000. }
  1001. $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  1002. $temp->resize($thumbwidth,$new_height,0);
  1003. }
  1004. $type=$picture_infos[2];
  1005. switch (!empty($type))
  1006. {
  1007. case 2 : $temp->send_image('JPG',$upload_dir.$new_file_name);
  1008. break;
  1009. case 3 : $temp->send_image('PNG',$upload_dir.$new_file_name);
  1010. break;
  1011. case 1 : $temp->send_image('GIF',$upload_dir.$new_file_name);
  1012. break;
  1013. }
  1014. }
  1015. }
  1016. // store the information in the database (as insert or as update)
  1017. $table_system_template = Database :: get_main_table('system_template');
  1018. if ($_GET['action'] == 'add') {
  1019. $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".Database::escape_string($values['template_text'])."','".Database::escape_string($new_file_name)."')";
  1020. $result = api_sql_query($sql, __FILE__, __LINE__);
  1021. // display a feedback message
  1022. Display::display_confirmation_message('TemplateAdded');
  1023. echo '<a href="settings.php?category=Templates&amp;action=add">'.Display::return_icon('add_template.gif', get_lang('AddTemplate')).get_lang('AddTemplate').'</a>';
  1024. } else {
  1025. $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."',
  1026. content = '".Database::escape_string($values['template_text'])."'";
  1027. if (!empty($new_file_name))
  1028. {
  1029. $sql .= ", image = '".Database::escape_string($new_file_name)."'";
  1030. }
  1031. $sql .= " WHERE id='".Database::escape_string($_GET['id'])."'";
  1032. $result = api_sql_query($sql, __FILE__, __LINE__);
  1033. // display a feedback message
  1034. Display::display_confirmation_message('TemplateEdited');
  1035. }
  1036. display_templates();
  1037. }
  1038. else
  1039. {
  1040. // display the form
  1041. $form->display();
  1042. }
  1043. }
  1044. /**
  1045. * Delete a template
  1046. *
  1047. * @param integer $id the id of the template that has to be deleted
  1048. *
  1049. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1050. * @version August 2008
  1051. * @since Dokeos 1.8.6
  1052. */
  1053. function delete_template($id)
  1054. {
  1055. // first we remove the image
  1056. $table_system_template = Database :: get_main_table('system_template');
  1057. $sql = "SELECT * FROM $table_system_template WHERE id = '".Database::escape_string($id)."'";
  1058. $result = api_sql_query($sql, __FILE__, __LINE__);
  1059. $row = Database::fetch_array($result);
  1060. if (!empty($row['image']))
  1061. {
  1062. unlink(api_get_path(SYS_PATH).'home/default_platform_document/'.$row['image']);
  1063. }
  1064. // now we remove it from the database
  1065. $sql = "DELETE FROM $table_system_template WHERE id = '".Database::escape_string($id)."'";
  1066. $result = api_sql_query($sql, __FILE__, __LINE__);
  1067. // display a feedback message
  1068. Display::display_confirmation_message('TemplateDeleted');
  1069. }
  1070. ?>