settings.php 30 KB

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