settings.php 24 KB

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