settings.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <?php // $Id: settings.php 16878 2008-11-23 00:04:52Z herodoto $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 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. // Access restrictions
  50. api_protect_admin_script();
  51. // Submit Stylesheets
  52. if (!empty($_POST['submit_stylesheets']))
  53. {
  54. $message = store_stylesheets();
  55. header("Location: ".api_get_self()."?category=stylesheets");
  56. exit;
  57. }
  58. // Database Table Definitions
  59. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  60. // setting breadcrumbs
  61. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  62. // setting the name of the tool
  63. $tool_name = get_lang('DokeosConfigSettings');
  64. // Build the form
  65. if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['category'] <> "stylesheets")
  66. {
  67. $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
  68. $renderer = & $form->defaultRenderer();
  69. $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
  70. $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
  71. $my_category = mysql_real_escape_string($_GET['category']);
  72. if ($_configuration['access_url']==1)
  73. {
  74. $settings = api_get_settings($my_category,'group',$_configuration['access_url']);
  75. }
  76. else
  77. {
  78. $url_info = api_get_access_url($_configuration['access_url']);
  79. if ($url_info['active']==1)
  80. {
  81. //the default settings of Dokeos
  82. $settings = api_get_settings($my_category,'group',1,0);
  83. //the settings that are changeable from a particular site
  84. $settings_by_access = api_get_settings($my_category,'group',$_configuration['access_url'],1);
  85. //echo '<pre>';
  86. //print_r($settings_by_access);
  87. $settings_by_access_list=array();
  88. foreach($settings_by_access as $row)
  89. {
  90. if (empty($row['variable']))
  91. $row['variable']=0;
  92. if (empty($row['subkey']))
  93. $row['subkey']=0;
  94. if (empty($row['category']))
  95. $row['category']=0;
  96. // one more validation if is changeable
  97. if ($row['access_url_changeable']==1)
  98. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  99. else
  100. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  101. }
  102. }
  103. }
  104. //print_r($settings_by_access_list);echo '</pre>';
  105. //$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
  106. //$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__);
  107. //while ($row = mysql_fetch_array($resultsettings))
  108. $default_values = array();
  109. foreach($settings as $row)
  110. {
  111. $form->addElement('header', null, get_lang($row['title']));
  112. $hideme=array();
  113. $hide_element=false;
  114. if ($_configuration['access_url']!=1)
  115. {
  116. if ($row['access_url_changeable']==0)
  117. {
  118. //we hide the element in other cases (checkbox, radiobutton) we 'freeze' the element
  119. $hide_element=true;
  120. $hideme=array('disabled');
  121. }
  122. elseif($url_info['active']==1)
  123. {
  124. // we show the elements
  125. if (empty($row['variable']))
  126. $row['variable']=0;
  127. if (empty($row['subkey']))
  128. $row['subkey']=0;
  129. if (empty($row['category']))
  130. $row['category']=0;
  131. if (is_array ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]))
  132. {
  133. // we are sure that the other site have a selected value
  134. if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value']!='')
  135. $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value'];
  136. }
  137. // there is no else because we load the default $row['selected_value'] of the main Dokeos site
  138. }
  139. }
  140. switch ($row['type'])
  141. {
  142. case 'textfield' :
  143. $form->addElement('text', $row['variable'], get_lang($row['comment']),$hideme);
  144. $default_values[$row['variable']] = $row['selected_value'];
  145. break;
  146. case 'textarea' :
  147. $form->addElement('textarea', $row['variable'], get_lang($row['comment']),$hideme);
  148. $default_values[$row['variable']] = $row['selected_value'];
  149. break;
  150. case 'radio' :
  151. $values = get_settings_options($row['variable']);
  152. $group = array ();
  153. foreach ($values as $key => $value)
  154. {
  155. $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
  156. if ($hide_element)
  157. $element->freeze();
  158. $group[] = $element;
  159. }
  160. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />', false);
  161. $default_values[$row['variable']] = $row['selected_value'];
  162. break;
  163. case 'checkbox';
  164. $sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."'";
  165. $result = api_sql_query($sql, __FILE__, __LINE__);
  166. $group = array ();
  167. while ($rowkeys = mysql_fetch_array($result))
  168. {
  169. $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
  170. if ($rowkeys['selected_value'] == 'true' && ! $form->isSubmitted())
  171. {
  172. $element->setChecked(true);
  173. }
  174. if ($hide_element)
  175. $element->freeze();
  176. $group[] = $element;
  177. }
  178. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />'."\n");
  179. break;
  180. case "link" :
  181. $form->addElement('static', null, get_lang($row['comment']), get_lang('CurrentValue').' : '.$row['selected_value'],$hideme);
  182. }
  183. }
  184. $form->addElement('submit', null, get_lang('Ok'));
  185. $form->setDefaults($default_values);
  186. if ($form->validate())
  187. {
  188. $values = $form->exportValues();
  189. // the first step is to set all the variables that have type=checkbox of the category
  190. // to false as the checkbox that is unchecked is not in the $_POST data and can
  191. // therefore not be set to false.
  192. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  193. // will be set to false.
  194. $r = api_set_settings_category($my_category,'false',$_configuration['access_url']);
  195. //$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'";
  196. //$result = api_sql_query($sql, __FILE__, __LINE__);
  197. // Save the settings
  198. foreach ($values as $key => $value)
  199. {
  200. if (!is_array($value))
  201. {
  202. //$sql = "UPDATE $table_settings_current SET selected_value='".mysql_real_escape_string($value)."' WHERE variable='$key'";
  203. //$result = api_sql_query($sql, __FILE__, __LINE__);
  204. $result = api_set_setting($key,$value,null,null,$_configuration['access_url']);
  205. }
  206. else
  207. {
  208. foreach ($value as $subkey => $subvalue)
  209. {
  210. //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'";
  211. //$result = api_sql_query($sql, __FILE__, __LINE__);
  212. $result = api_set_setting($key,'true',$subkey,null,$_configuration['access_url']);
  213. }
  214. }
  215. }
  216. header('Location: settings.php?action=stored&category='.$_GET['category']);
  217. exit;
  218. }
  219. }
  220. // including the header (banner)
  221. Display :: display_header($tool_name);
  222. //api_display_tool_title($tool_name);
  223. // displaying the message that the settings have been stored
  224. if (!empty($_GET['action']) && $_GET['action'] == "stored")
  225. {
  226. Display :: display_normal_message($SettingsStored);
  227. }
  228. // the action images
  229. $action_images['platform'] = 'dokeos.gif';
  230. $action_images['course'] = 'lp_dokeos_module.gif';
  231. $action_images['tools'] = 'reference.gif';
  232. $action_images['user'] = 'students.gif';
  233. $action_images['gradebook'] = 'gradebook_eval_not_empty.gif';
  234. $action_images['ldap'] = 'loginmanager.gif';
  235. $action_images['security'] = 'passwordprotected.gif';
  236. $action_images['languages'] = 'forum.gif';
  237. $action_images['tuning'] = 'tuning.gif';
  238. $action_images['plugins'] = 'plugin.gif';
  239. $action_images['stylesheets'] = 'theme.gif';
  240. // grabbing the categories
  241. //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
  242. //$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__);
  243. $resultcategories = api_get_settings_categories(array('stylesheets','Plugins'));
  244. echo "\n<div class=\"actions\">";
  245. //while ($row = mysql_fetch_array($resultcategories))
  246. foreach($resultcategories as $row)
  247. {
  248. echo "\n\t<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], ucfirst(get_lang($row['category']))).ucfirst(get_lang($row['category']))."</a>";
  249. }
  250. echo "\n\t<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], ucfirst(get_lang('Plugins'))).ucfirst(get_lang('Plugins'))."</a>";
  251. echo "\n\t<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], ucfirst(get_lang('Stylesheets'))).ucfirst(get_lang('Stylesheets'))."</a>";
  252. echo "\n</div>";
  253. if (isset ($_GET['category']))
  254. {
  255. switch ($_GET['category'])
  256. {
  257. // displaying the extensions: plugins
  258. // this will be available to all the sites (access_urls)
  259. case 'Plugins' :
  260. handle_plugins();
  261. break;
  262. // displaying the extensions: Stylesheets
  263. case 'stylesheets' :
  264. handle_stylesheets();
  265. break;
  266. default :
  267. $form->display();
  268. }
  269. }
  270. /*
  271. ==============================================================================
  272. FOOTER
  273. ==============================================================================
  274. */
  275. Display :: display_footer();
  276. /*
  277. ==============================================================================
  278. FUNCTIONS
  279. ==============================================================================
  280. */
  281. /**
  282. * The function that retrieves all the possible settings for a certain config setting
  283. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  284. */
  285. function get_settings_options($var)
  286. {
  287. $table_settings_options = Database :: get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  288. $sql = "SELECT * FROM $table_settings_options WHERE variable='$var'";
  289. $result = api_sql_query($sql, __FILE__, __LINE__);
  290. while ($row = mysql_fetch_array($result))
  291. {
  292. $temp_array = array ('value' => $row['value'], 'display_text' => $row['display_text']);
  293. $settings_options_array[] = $temp_array;
  294. }
  295. return $settings_options_array;
  296. }
  297. /**
  298. * This function allows easy activating and inactivating of plugins
  299. * @todo: a similar function needs to be written to activate or inactivate additional tools.
  300. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  301. */
  302. function handle_plugins()
  303. {
  304. global $SettingsStored;
  305. $userplugins = array();
  306. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  307. if (!empty($_POST['submit_plugins']))
  308. {
  309. store_plugins();
  310. Display :: display_normal_message($SettingsStored);
  311. }
  312. echo get_lang('AvailablePlugins')."<br/><br/>";
  313. /* We scan the plugin directory. Each folder is a potential plugin. */
  314. $pluginpath = api_get_path(SYS_PLUGIN_PATH);
  315. $handle = @opendir($pluginpath);
  316. while (false !== ($file = readdir($handle)))
  317. {
  318. if ($file <> '.' AND $file <> '..' AND is_dir(api_get_path(SYS_PLUGIN_PATH).$file))
  319. {
  320. $possibleplugins[] = $file;
  321. }
  322. }
  323. @closedir($handle);
  324. /* for each of the possible plugin dirs we check if a file plugin.php (that contains all the needed information about this plugin)
  325. can be found in the dir.
  326. this plugin.php file looks like
  327. $plugin_info['title']='The title of the plugin'; //
  328. $plugin_info['comment']="Some comment about the plugin";
  329. $plugin_info['location']=array("loginpage_menu", "campushomepage_menu","banner"); // the possible locations where the plugins can be used
  330. $plugin_info['version']='0.1 alpha'; // The version number of the plugin
  331. $plugin_info['author']='Patrick Cool'; // The author of the plugin
  332. */
  333. echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.$_GET['category'].'">';
  334. echo "<table class=\"data_table\">\n";
  335. echo "\t<tr>\n";
  336. echo "\t\t<th>\n";
  337. echo get_lang('Plugin');
  338. echo "\t\t</th>\n";
  339. echo "\t\t<th>\n";
  340. echo get_lang('LoginPageMainArea');
  341. echo "\t\t</th>\n";
  342. echo "\t\t<th>\n";
  343. echo get_lang('LoginPageMenu');
  344. echo "\t\t</th>\n";
  345. echo "\t\t<th>\n";
  346. echo get_lang('CampusHomepageMainArea');
  347. echo "\t\t</th>\n";
  348. echo "\t\t<th>\n";
  349. echo get_lang('CampusHomepageMenu');
  350. echo "\t\t</th>\n";
  351. echo "\t\t<th>\n";
  352. echo get_lang('MyCoursesMainArea');
  353. echo "\t\t</th>\n";
  354. echo "\t\t<th>\n";
  355. echo get_lang('MyCoursesMenu');
  356. echo "\t\t</th>\n";
  357. echo "\t\t<th>\n";
  358. echo get_lang('Header');
  359. echo "\t\t</th>\n";
  360. echo "\t\t<th>\n";
  361. echo get_lang('Footer');
  362. echo "\t\t</th>\n";
  363. echo "\t</tr>\n";
  364. /* We retrieve all the active plugins. */
  365. //$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'";
  366. //$result = api_sql_query($sql);
  367. $result = api_get_settings('Plugins');
  368. //while ($row = mysql_fetch_array($result))
  369. foreach($result as $row)
  370. {
  371. $usedplugins[$row['variable']][] = $row['selected_value'];
  372. }
  373. /* We display all the possible plugins and the checkboxes */
  374. foreach ($possibleplugins as $testplugin)
  375. {
  376. $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$testplugin."/plugin.php";
  377. if (file_exists($plugin_info_file))
  378. {
  379. $plugin_info = array();
  380. include ($plugin_info_file);
  381. echo "\t<tr>\n";
  382. echo "\t\t<td>\n";
  383. foreach ($plugin_info as $key => $value)
  384. {
  385. if ($key <> 'location')
  386. {
  387. if ($key == 'title')
  388. {
  389. $value = '<strong>'.$value.'</strong>';
  390. }
  391. echo get_lang(ucwords($key)).': '.$value.'<br />';
  392. }
  393. }
  394. if (file_exists(api_get_path(SYS_PLUGIN_PATH).$testplugin.'/readme.txt'))
  395. {
  396. echo "<a href='".api_get_path(WEB_PLUGIN_PATH).$testplugin."/readme.txt'>readme.txt</a>";
  397. }
  398. echo "\t\t</td>\n";
  399. // column: LoginPageMainArea
  400. if(empty($usedplugins))
  401. {
  402. $usedplugins = array();
  403. }
  404. display_plugin_cell('loginpage_main', $plugin_info, $testplugin, $usedplugins);
  405. display_plugin_cell('loginpage_menu', $plugin_info, $testplugin, $usedplugins);
  406. display_plugin_cell('campushomepage_main', $plugin_info, $testplugin, $usedplugins);
  407. display_plugin_cell('campushomepage_menu', $plugin_info, $testplugin, $usedplugins);
  408. display_plugin_cell('mycourses_main', $plugin_info, $testplugin, $usedplugins);
  409. display_plugin_cell('mycourses_menu', $plugin_info, $testplugin, $usedplugins);
  410. display_plugin_cell('header', $plugin_info, $testplugin, $usedplugins);
  411. display_plugin_cell('footer', $plugin_info, $testplugin, $usedplugins);
  412. echo "\t</tr>\n";
  413. }
  414. }
  415. echo '</table>';
  416. echo '<input type="submit" name="submit_plugins" value="'.get_lang('Ok').'" /></form>';
  417. }
  418. function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins)
  419. {
  420. echo "\t\t<td align=\"center\">\n";
  421. if (in_array($location, $plugin_info['location']))
  422. {
  423. if (isset($active_plugins[$location]) && is_array($active_plugins[$location])
  424. && in_array($current_plugin, $active_plugins[$location]))
  425. {
  426. $checked = "checked";
  427. }
  428. else
  429. {
  430. $checked = '';
  431. }
  432. echo '<input type="checkbox" name="'.$current_plugin.'-'.$location.'" value="true" '.$checked.'/>';
  433. }
  434. echo "\t\t</td>\n";
  435. }
  436. /**
  437. * This function allows the platform admin to choose the default stylesheet
  438. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  439. */
  440. function handle_stylesheets()
  441. {
  442. global $_configuration;
  443. // Current style
  444. $currentstyle = api_get_setting('stylesheets');
  445. $is_style_changeable=false;
  446. if ($_configuration['access_url']!=1)
  447. {
  448. $style_info = api_get_settings('stylesheets','',1,0);
  449. $url_info = api_get_access_url($_configuration['access_url']);
  450. if ($style_info[0]['access_url_changeable']==1 && $url_info['active']==1)
  451. {
  452. $is_style_changeable=true;
  453. echo '<a href="" id="stylesheetuploadlink" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">'.get_lang('UploadNewStylesheet').'</a>';
  454. }
  455. }
  456. else
  457. {
  458. $is_style_changeable=true;
  459. echo '<a href="" id="stylesheetuploadlink" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">'.get_lang('UploadNewStylesheet').'</a>';
  460. }
  461. $form = new FormValidator('stylesheet_upload','post','settings.php?category=stylesheets&showuploadform=true');
  462. $form->addElement('text','name_stylesheet',get_lang('NameStylesheet'),array('size' => '40', 'maxlength' => '40'));
  463. $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
  464. $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
  465. $allowed_file_types = array ('css');
  466. $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types);
  467. $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
  468. $form->addElement('submit', 'stylesheet_upload', get_lang('Ok'));
  469. if( $form->validate() AND is_writable(api_get_path(SYS_CODE_PATH).'css/'))
  470. {
  471. $values = $form->exportValues();
  472. $picture_element = & $form->getElement('new_stylesheet');
  473. $picture = $picture_element->getValue();
  474. upload_stylesheet($values, $picture);
  475. Display::display_confirmation_message(get_lang('StylesheetAdded'));
  476. }
  477. else
  478. {
  479. if (!is_writable(api_get_path(SYS_CODE_PATH).'css/'))
  480. {
  481. Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable'));
  482. }
  483. else
  484. {
  485. if ($_GET['showuploadform'] == 'true')
  486. {
  487. echo '<div id="newstylesheetform">';
  488. }
  489. else
  490. {
  491. echo '<div id="newstylesheetform" style="display: none;">';
  492. }
  493. // uploading a new stylesheet
  494. if ($_configuration['access_url']==1)
  495. {
  496. $form->display();
  497. }
  498. else
  499. {
  500. if ($is_style_changeable)
  501. {
  502. $form->display();
  503. }
  504. }
  505. echo '</div>';
  506. }
  507. }
  508. // Preview of the stylesheet
  509. echo '<div><iframe src="style_preview.php" width="100%" height="300" name="preview"></iframe></div>';
  510. echo '<form name="stylesheets" method="post" action="'.api_get_self().'?category='.$_GET['category'].'">';
  511. if ($handle = @opendir(api_get_path(SYS_PATH).'main/css/'))
  512. {
  513. $counter=1;
  514. while (false !== ($style_dir = readdir($handle)))
  515. {
  516. if(substr($style_dir,0,1)=='.') //skip dirs starting with a '.'
  517. {
  518. continue;
  519. }
  520. $dirpath = api_get_path(SYS_PATH).'main/css/'.$style_dir;
  521. if (is_dir($dirpath))
  522. {
  523. if ($style_dir != '.' && $style_dir != '..')
  524. {
  525. if ($currentstyle == $style_dir OR ($style_dir == 'dokeos_classic' AND !$currentstyle))
  526. {
  527. $selected = 'checked="checked"';
  528. }
  529. else
  530. {
  531. $selected = '';
  532. }
  533. $show_name=ucwords(str_replace('_',' ', $style_dir));
  534. if ($is_style_changeable)
  535. {
  536. echo "<input type=\"radio\" name=\"style\" value=\"".$style_dir."\" ".$selected." onClick=\"parent.preview.location='style_preview.php?style=".$style_dir."';\"/>";
  537. echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
  538. }
  539. else
  540. echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
  541. //echo '<div id="Layer'.$counter.'" style="position:relative; width:687px; z-index:2; visibility: hidden;">';
  542. //echo '<a href="#" onClick="MM_showHideLayers(\'Layer'.$counter.'\',\'\',\'hide\')">'.get_lang('Close').'</a>';
  543. //echo '<iframe src="style_preview.php?style='.$file.'" width="100%" style="float:right;"></iframe></div>';
  544. echo "<br />\n";
  545. $counter++;
  546. }
  547. }
  548. }
  549. @closedir($handle);
  550. }
  551. if ($is_style_changeable)
  552. {
  553. echo '<input type="submit" name="submit_stylesheets" value="'.get_lang('Ok').'" /></form>';
  554. }
  555. }
  556. /**
  557. * creates the folder (if needed) and uploads the stylesheet in it
  558. *
  559. * @param array $values the values of the form
  560. * @param array $picture the values of the uploaded file
  561. *
  562. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  563. * @version May 2008
  564. * @since Dokeos 1.8.5
  565. */
  566. function upload_stylesheet($values,$picture)
  567. {
  568. // valid name for the stylesheet folder
  569. $style_name = ereg_replace("[^A-Za-z0-9]", "", $values['name_stylesheet'] );
  570. // create the folder if needed
  571. if(!is_dir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'))
  572. {
  573. if(mkdir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'))
  574. {
  575. $perm = api_get_setting('permissions_for_new_directories');
  576. $perm = octdec(!empty($perm)?$perm:'0770');
  577. chmod(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/');
  578. }
  579. }
  580. // move the file in the folder
  581. move_uploaded_file($picture['tmp_name'], api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'.$picture['name']);
  582. }
  583. /**
  584. * This function allows easy activating and inactivating of plugins
  585. * @todo: a similar function needs to be written to activate or inactivate additional tools.
  586. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  587. */
  588. function store_plugins()
  589. {
  590. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  591. global $_configuration;
  592. // Step 1 : we remove all the plugins
  593. //$sql = "DELETE FROM $table_settings_current WHERE category='Plugins'";
  594. //api_sql_query($sql, __LINE__, __FILE__);
  595. $r = api_delete_category_settings('Plugins',$_configuration['access_url']);
  596. // step 2: looping through all the post values we only store these which are really a valid plugin location.
  597. foreach ($_POST as $form_name => $formvalue)
  598. {
  599. $form_name_elements = explode("-", $form_name);
  600. if (is_valid_plugin_location($form_name_elements[1]))
  601. {
  602. //$sql = "INSERT into $table_settings_current (variable,category,selected_value) VALUES ('".$form_name_elements['1']."','Plugins','".$form_name_elements['0']."')";
  603. //api_sql_query($sql, __LINE__, __FILE__);
  604. 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);
  605. }
  606. }
  607. }
  608. /**
  609. * Check if the post information is really a valid plugin location.
  610. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  611. */
  612. function is_valid_plugin_location($location)
  613. {
  614. $valid_locations=array('loginpage_main', 'loginpage_menu', 'campushomepage_main', 'campushomepage_menu', 'mycourses_main', 'mycourses_menu','header', 'footer');
  615. if (in_array($location, $valid_locations))
  616. {
  617. return true;
  618. }
  619. else
  620. {
  621. return false;
  622. }
  623. }
  624. /**
  625. * This function allows the platform admin to choose which should be the default stylesheet
  626. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  627. */
  628. function store_stylesheets()
  629. {
  630. global $_configuration;
  631. // Database Table Definitions
  632. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  633. // Insert the stylesheet
  634. $style = Database::escape_string($_POST['style']);
  635. if (is_style($style))
  636. {
  637. /*
  638. $sql = 'UPDATE '.$table_settings_current.' SET
  639. selected_value = "'.$style.'"
  640. WHERE variable = "stylesheets"
  641. AND category = "stylesheets"';
  642. api_sql_query($sql, __LINE__, __FILE__);
  643. */
  644. api_set_setting('stylesheets',$style,null,'stylesheets',$_configuration['access_url']);
  645. }
  646. return true;
  647. }
  648. /**
  649. * This function checks if the given style is a recognize style that exists in the css directory as
  650. * a standalone directory.
  651. * @param string Style
  652. * @return bool True if this style is recognized, false otherwise
  653. */
  654. function is_style($style)
  655. {
  656. $dir = api_get_path(SYS_PATH).'main/css/';
  657. $dirs = scandir($dir);
  658. $style = str_replace(array('/','\\'),array('',''),$style); //avoid slashes or backslashes
  659. if (in_array($style,$dirs) && is_dir($dir.$style))
  660. {
  661. return true;
  662. }
  663. return false;
  664. }
  665. ?>