plugin.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Plugin
  5. * Base class for plugins
  6. *
  7. * This class has to be extended by every plugin. It defines basic methods
  8. * to install/uninstall and get information about a plugin
  9. *
  10. * @author Julio Montoya <gugli100@gmail.com>
  11. * @author Yannick Warnier <ywarnier@beeznest.org>
  12. * @author Laurent Opprecht <laurent@opprecht.info>
  13. * @copyright 2012 University of Geneva
  14. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  15. *
  16. */
  17. class Plugin
  18. {
  19. protected $version = '';
  20. protected $author = '';
  21. protected $fields = [];
  22. private $settings = [];
  23. // Translation strings.
  24. private $strings = null;
  25. public $isCoursePlugin = false;
  26. public $isAdminPlugin = false;
  27. public $isMailPlugin = false;
  28. // Adds icon in the course home
  29. public $addCourseTool = true;
  30. /**
  31. * When creating a new course, these settings are added to the course, in
  32. * the course_info/infocours.php
  33. * To show the plugin course icons you need to add these icons:
  34. * main/img/icons/22/plugin_name.png
  35. * main/img/icons/64/plugin_name.png
  36. * main/img/icons/64/plugin_name_na.png
  37. * @example
  38. * $course_settings = array(
  39. array('name' => 'big_blue_button_welcome_message', 'type' => 'text'),
  40. array('name' => 'big_blue_button_record_and_store', 'type' => 'checkbox')
  41. );
  42. */
  43. public $course_settings = array();
  44. /**
  45. * This indicates whether changing the setting should execute the callback
  46. * function.
  47. */
  48. public $course_settings_callback = false;
  49. /**
  50. * Default constructor for the plugin class. By default, it only sets
  51. * a few attributes of the object
  52. * @param string $version of this plugin
  53. * @param string $author of this plugin
  54. * @param array $settings settings to be proposed to configure the plugin
  55. */
  56. protected function __construct($version, $author, $settings = array())
  57. {
  58. $this->version = $version;
  59. $this->author = $author;
  60. $this->fields = $settings;
  61. global $language_files;
  62. $language_files[] = 'plugin_'.$this->get_name();
  63. }
  64. /**
  65. * Gets an array of information about this plugin (name, version, ...)
  66. * @return array Array of information elements about this plugin
  67. */
  68. public function get_info()
  69. {
  70. $result = array();
  71. $result['obj'] = $this;
  72. $result['title'] = $this->get_title();
  73. $result['comment'] = $this->get_comment();
  74. $result['version'] = $this->get_version();
  75. $result['author'] = $this->get_author();
  76. $result['plugin_class'] = get_class($this);
  77. $result['is_course_plugin'] = $this->isCoursePlugin;
  78. $result['is_admin_plugin'] = $this->isAdminPlugin;
  79. $result['is_mail_plugin'] = $this->isMailPlugin;
  80. if ($form = $this->get_settings_form()) {
  81. $result['settings_form'] = $form;
  82. foreach ($this->fields as $name => $type) {
  83. $value = $this->get($name);
  84. if (is_array($type)) {
  85. $value = $type['options'];
  86. }
  87. $result[$name] = $value;
  88. }
  89. }
  90. return $result;
  91. }
  92. /**
  93. * Returns the "system" name of the plugin in lowercase letters
  94. * @return string
  95. */
  96. public function get_name()
  97. {
  98. $result = get_class($this);
  99. $result = str_replace('Plugin', '', $result);
  100. $result = strtolower($result);
  101. return $result;
  102. }
  103. /**
  104. * @return string
  105. */
  106. public function getCamelCaseName()
  107. {
  108. $result = get_class($this);
  109. return str_replace('Plugin', '', $result);
  110. }
  111. /**
  112. * Returns the title of the plugin
  113. * @return string
  114. */
  115. public function get_title()
  116. {
  117. return $this->get_lang('plugin_title');
  118. }
  119. /**
  120. * Returns the description of the plugin
  121. * @return string
  122. */
  123. public function get_comment()
  124. {
  125. return $this->get_lang('plugin_comment');
  126. }
  127. /**
  128. * Returns the version of the plugin
  129. * @return string
  130. */
  131. public function get_version()
  132. {
  133. return $this->version;
  134. }
  135. /**
  136. * Returns the author of the plugin
  137. * @return string
  138. */
  139. public function get_author()
  140. {
  141. return $this->author;
  142. }
  143. /**
  144. * Returns the contents of the CSS defined by the plugin
  145. * @return string
  146. */
  147. public function get_css()
  148. {
  149. $name = $this->get_name();
  150. $path = api_get_path(SYS_PLUGIN_PATH)."$name/resources/$name.css";
  151. if (!is_readable($path)) {
  152. return '';
  153. }
  154. $css = array();
  155. $css[] = file_get_contents($path);
  156. $result = implode($css);
  157. return $result;
  158. }
  159. /**
  160. * Returns an HTML form (generated by FormValidator) of the plugin settings
  161. * @return FormValidator FormValidator-generated form
  162. */
  163. public function get_settings_form()
  164. {
  165. $result = new FormValidator($this->get_name());
  166. $defaults = array();
  167. $checkboxGroup = array();
  168. $checkboxCollection = array();
  169. if ($checkboxNames = array_keys($this->fields, 'checkbox')) {
  170. $pluginInfoCollection = api_get_settings('Plugins');
  171. foreach ($pluginInfoCollection as $pluginInfo) {
  172. if (array_search($pluginInfo['title'], $checkboxNames) !== false) {
  173. $checkboxCollection[$pluginInfo['title']] = $pluginInfo;
  174. }
  175. }
  176. }
  177. foreach ($this->fields as $name => $type) {
  178. $options = null;
  179. if (is_array($type) && isset($type['type']) && $type['type'] === 'select') {
  180. $options = $type['options'];
  181. $type = $type['type'];
  182. }
  183. $value = $this->get($name);
  184. $defaults[$name] = $value;
  185. $type = isset($type) ? $type : 'text';
  186. $help = null;
  187. if ($this->get_lang_plugin_exists($name.'_help')) {
  188. $help = $this->get_lang($name.'_help');
  189. if ($name === "show_main_menu_tab") {
  190. $pluginName = strtolower(str_replace('Plugin', '', get_class($this)));
  191. $pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php";
  192. $pluginUrl = "<a href=$pluginUrl>$pluginUrl</a>";
  193. $help = sprintf($help, $pluginUrl);
  194. }
  195. }
  196. switch ($type) {
  197. case 'html':
  198. $result->addElement('html', $this->get_lang($name));
  199. break;
  200. case 'wysiwyg':
  201. $result->addHtmlEditor($name, $this->get_lang($name), false);
  202. break;
  203. case 'text':
  204. $result->addElement($type, $name, array($this->get_lang($name), $help));
  205. break;
  206. case 'boolean':
  207. $group = array();
  208. $group[] = $result->createElement('radio', $name, '', get_lang('Yes'), 'true');
  209. $group[] = $result->createElement('radio', $name, '', get_lang('No'), 'false');
  210. $result->addGroup($group, null, array($this->get_lang($name), $help));
  211. break;
  212. case 'checkbox':
  213. $selectedValue = null;
  214. if (isset($checkboxCollection[$name])) {
  215. if ($checkboxCollection[$name]['selected_value'] === 'true') {
  216. $selectedValue = 'checked';
  217. }
  218. }
  219. $element = $result->createElement(
  220. $type,
  221. $name,
  222. '',
  223. $this->get_lang($name),
  224. $selectedValue
  225. );
  226. $element->_attributes['value'] = 'true';
  227. $checkboxGroup[] = $element;
  228. break;
  229. case 'select':
  230. $result->addElement(
  231. $type,
  232. $name,
  233. array($this->get_lang($name), $help),
  234. $options
  235. );
  236. break;
  237. }
  238. }
  239. if (!empty($checkboxGroup)) {
  240. $result->addGroup($checkboxGroup, null, array($this->get_lang('sms_types'), $help));
  241. }
  242. $result->setDefaults($defaults);
  243. $result->addButtonSave($this->get_lang('Save'), 'submit_button');
  244. return $result;
  245. }
  246. /**
  247. * Returns the value of a given plugin global setting
  248. * @param string $name of the plugin
  249. *
  250. * @return string Value of the plugin
  251. */
  252. public function get($name)
  253. {
  254. $settings = $this->get_settings();
  255. foreach ($settings as $setting) {
  256. if ($setting['variable'] == $this->get_name().'_'.$name) {
  257. return $setting['selected_value'];
  258. }
  259. }
  260. return false;
  261. }
  262. /**
  263. * Returns an array with the global settings for this plugin
  264. * @return array Plugin settings as an array
  265. */
  266. public function get_settings()
  267. {
  268. if (empty($this->settings)) {
  269. $settings = api_get_settings_params(
  270. array(
  271. "subkey = ? AND category = ? AND type = ? " => array($this->get_name(), 'Plugins', 'setting')
  272. )
  273. );
  274. $this->settings = $settings;
  275. }
  276. return $this->settings;
  277. }
  278. /**
  279. * Tells whether language variables are defined for this plugin or not
  280. * @param string $name System name of the plugin
  281. *
  282. * @return bool True if the plugin has language variables defined, false otherwise
  283. */
  284. public function get_lang_plugin_exists($name)
  285. {
  286. return isset($this->strings[$name]);
  287. }
  288. /**
  289. * Hook for the get_lang() function to check for plugin-defined language terms
  290. * @param string $name of the language variable we are looking for
  291. *
  292. * @return string The translated language term of the plugin
  293. */
  294. public function get_lang($name)
  295. {
  296. // Check whether the language strings for the plugin have already been
  297. // loaded. If so, no need to load them again.
  298. if (is_null($this->strings)) {
  299. global $language_interface;
  300. $root = api_get_path(SYS_PLUGIN_PATH);
  301. $plugin_name = $this->get_name();
  302. $interfaceLanguageId = api_get_language_id($language_interface);
  303. $interfaceLanguageInfo = api_get_language_info($interfaceLanguageId);
  304. $languageParentId = !empty($interfaceLanguageInfo['parent_id']) ? (int) $interfaceLanguageInfo['parent_id'] : 0;
  305. //1. Loading english if exists
  306. $english_path = $root.$plugin_name."/lang/english.php";
  307. if (is_readable($english_path)) {
  308. $strings = array();
  309. include $english_path;
  310. $this->strings = $strings;
  311. }
  312. $path = $root.$plugin_name."/lang/$language_interface.php";
  313. // 2. Loading the system language
  314. if (is_readable($path)) {
  315. include $path;
  316. if (!empty($strings)) {
  317. foreach ($strings as $key => $string) {
  318. $this->strings[$key] = $string;
  319. }
  320. }
  321. } elseif ($languageParentId > 0) {
  322. $languageParentInfo = api_get_language_info($languageParentId);
  323. $languageParentFolder = $languageParentInfo['dokeos_folder'];
  324. $parentPath = "{$root}{$plugin_name}/lang/{$languageParentFolder}.php";
  325. if (is_readable($parentPath)) {
  326. include $parentPath;
  327. if (!empty($strings)) {
  328. foreach ($strings as $key => $string) {
  329. $this->strings[$key] = $string;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. if (isset($this->strings[$name])) {
  336. return $this->strings[$name];
  337. }
  338. return get_lang($name);
  339. }
  340. /**
  341. * Caller for the install_course_fields() function
  342. * @param int $courseId
  343. *
  344. * @param boolean $addToolLink Whether to add a tool link on the course homepage
  345. *
  346. * @return void
  347. */
  348. public function course_install($courseId, $addToolLink = true)
  349. {
  350. $this->install_course_fields($courseId, $addToolLink);
  351. }
  352. /**
  353. * Add course settings and, if not asked otherwise, add a tool link on the course homepage
  354. * @param int $courseId Course integer ID
  355. * @param boolean $add_tool_link Whether to add a tool link or not
  356. * (some tools might just offer a configuration section and act on the backend)
  357. *
  358. * @return boolean|null False on error, null otherwise
  359. */
  360. public function install_course_fields($courseId, $add_tool_link = true)
  361. {
  362. $plugin_name = $this->get_name();
  363. $t_course = Database::get_course_table(TABLE_COURSE_SETTING);
  364. $courseId = (int) $courseId;
  365. if (empty($courseId)) {
  366. return false;
  367. }
  368. // Adding course settings.
  369. if (!empty($this->course_settings)) {
  370. foreach ($this->course_settings as $setting) {
  371. $variable = $setting['name'];
  372. $value = '';
  373. if (isset($setting['init_value'])) {
  374. $value = $setting['init_value'];
  375. }
  376. $type = 'textfield';
  377. if (isset($setting['type'])) {
  378. $type = $setting['type'];
  379. }
  380. if (isset($setting['group'])) {
  381. $group = $setting['group'];
  382. $sql = "SELECT value
  383. FROM $t_course
  384. WHERE
  385. c_id = $courseId AND
  386. variable = '".Database::escape_string($group)."' AND
  387. subkey = '".Database::escape_string($variable)."'
  388. ";
  389. $result = Database::query($sql);
  390. if (!Database::num_rows($result)) {
  391. $params = [
  392. 'c_id' => $courseId,
  393. 'variable' => $group,
  394. 'subkey' => $variable,
  395. 'value' => $value,
  396. 'category' => 'plugins',
  397. 'type' => $type,
  398. 'title' => ''
  399. ];
  400. Database::insert($t_course, $params);
  401. }
  402. } else {
  403. $sql = "SELECT value FROM $t_course
  404. WHERE c_id = $courseId AND variable = '$variable' ";
  405. $result = Database::query($sql);
  406. if (!Database::num_rows($result)) {
  407. $params = [
  408. 'c_id' => $courseId,
  409. 'variable' => $variable,
  410. 'subkey' => $plugin_name,
  411. 'value' => $value,
  412. 'category' => 'plugins',
  413. 'type' => $type,
  414. 'title' => ''
  415. ];
  416. Database::insert($t_course, $params);
  417. }
  418. }
  419. }
  420. }
  421. // Stop here if we don't want a tool link on the course homepage
  422. if (!$add_tool_link) {
  423. return true;
  424. }
  425. if ($this->addCourseTool == false) {
  426. return true;
  427. }
  428. //Add an icon in the table tool list
  429. $table = Database::get_course_table(TABLE_TOOL_LIST);
  430. $sql = "SELECT name FROM $table
  431. WHERE c_id = $courseId AND name = '$plugin_name' ";
  432. $result = Database::query($sql);
  433. if (!Database::num_rows($result)) {
  434. $tool_link = "$plugin_name/start.php";
  435. $cToolId = AddCourse::generateToolId($courseId);
  436. Database::insert(
  437. $table,
  438. [
  439. 'id' => $cToolId,
  440. 'c_id' => $courseId,
  441. 'name' => $plugin_name,
  442. 'link' => $tool_link,
  443. 'image' => "$plugin_name.png",
  444. 'visibility' => 1,
  445. 'admin' => 0,
  446. 'address' => 'squaregrey.gif',
  447. 'added_tool' => 0,
  448. 'target' => '_self',
  449. 'category' => 'plugin',
  450. 'session_id' => 0
  451. ]
  452. );
  453. }
  454. }
  455. /**
  456. * Delete the fields added to the course settings page and the link to the
  457. * tool on the course's homepage
  458. * @param int $courseId
  459. *
  460. * @return false|null
  461. */
  462. public function uninstall_course_fields($courseId)
  463. {
  464. $courseId = intval($courseId);
  465. if (empty($courseId)) {
  466. return false;
  467. }
  468. $plugin_name = $this->get_name();
  469. $t_course = Database::get_course_table(TABLE_COURSE_SETTING);
  470. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  471. if (!empty($this->course_settings)) {
  472. foreach ($this->course_settings as $setting) {
  473. $variable = Database::escape_string($setting['name']);
  474. if (!empty($setting['group'])) {
  475. $variable = Database::escape_string($setting['group']);
  476. }
  477. if (empty($variable)) {
  478. continue;
  479. }
  480. $sql = "DELETE FROM $t_course
  481. WHERE c_id = $courseId AND variable = '$variable'";
  482. Database::query($sql);
  483. }
  484. }
  485. $plugin_name = Database::escape_string($plugin_name);
  486. $sql = "DELETE FROM $t_tool
  487. WHERE c_id = $courseId AND name = '$plugin_name'";
  488. Database::query($sql);
  489. }
  490. /**
  491. * Install the course fields and tool link of this plugin in all courses
  492. * @param boolean $add_tool_link Whether we want to add a plugin link on the course homepage
  493. *
  494. * @return void
  495. */
  496. public function install_course_fields_in_all_courses($add_tool_link = true)
  497. {
  498. // Update existing courses to add plugin settings
  499. $t_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  500. $sql = "SELECT id FROM $t_courses ORDER BY id";
  501. $res = Database::query($sql);
  502. while ($row = Database::fetch_assoc($res)) {
  503. $this->install_course_fields($row['id'], $add_tool_link);
  504. }
  505. }
  506. /**
  507. * Uninstall the plugin settings fields from all courses
  508. * @return void
  509. */
  510. public function uninstall_course_fields_in_all_courses()
  511. {
  512. // Update existing courses to add conference settings
  513. $t_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  514. $sql = "SELECT id FROM $t_courses
  515. ORDER BY id";
  516. $res = Database::query($sql);
  517. while ($row = Database::fetch_assoc($res)) {
  518. $this->uninstall_course_fields($row['id']);
  519. }
  520. }
  521. /**
  522. * @return array
  523. */
  524. public function getCourseSettings()
  525. {
  526. $settings = array();
  527. if (is_array($this->course_settings)) {
  528. foreach ($this->course_settings as $item) {
  529. if (isset($item['group'])) {
  530. if (!in_array($item['group'], $settings)) {
  531. $settings[] = $item['group'];
  532. }
  533. } else {
  534. $settings[] = $item['name'];
  535. }
  536. }
  537. }
  538. return $settings;
  539. }
  540. /**
  541. * Method to be extended when changing the setting in the course
  542. * configuration should trigger the use of a callback method
  543. * @param array $values sent back from the course configuration script
  544. *
  545. * @return void
  546. */
  547. public function course_settings_updated($values = array())
  548. {
  549. }
  550. /**
  551. * Add a tab to platform
  552. * @param string $tabName
  553. * @param string $url
  554. *
  555. * @return false|string
  556. */
  557. public function addTab($tabName, $url)
  558. {
  559. $sql = "SELECT * FROM settings_current
  560. WHERE
  561. variable = 'show_tabs' AND
  562. subkey LIKE 'custom_tab_%'";
  563. $result = Database::query($sql);
  564. $customTabsNum = Database::num_rows($result);
  565. $tabNum = $customTabsNum + 1;
  566. // Avoid Tab Name Spaces
  567. $tabNameNoSpaces = preg_replace('/\s+/', '', $tabName);
  568. $subkeytext = "Tabs".$tabNameNoSpaces;
  569. // Check if it is already added
  570. $checkCondition = array(
  571. 'where' =>
  572. array(
  573. "variable = 'show_tabs' AND subkeytext = ?" => array(
  574. $subkeytext
  575. )
  576. )
  577. );
  578. $checkDuplicate = Database::select('*', 'settings_current', $checkCondition);
  579. if (!empty($checkDuplicate)) {
  580. return false;
  581. }
  582. // End Check
  583. $subkey = 'custom_tab_'.$tabNum;
  584. $attributes = array(
  585. 'variable' => 'show_tabs',
  586. 'subkey' => $subkey,
  587. 'type' => 'checkbox',
  588. 'category' => 'Platform',
  589. 'selected_value' => 'true',
  590. 'title' => $tabName,
  591. 'comment' => $url,
  592. 'subkeytext' => $subkeytext,
  593. 'access_url' => 1,
  594. 'access_url_changeable' => 0,
  595. 'access_url_locked' => 0
  596. );
  597. $resp = Database::insert('settings_current', $attributes);
  598. // Save the id
  599. $settings = $this->get_settings();
  600. $setData = array(
  601. 'comment' => $subkey
  602. );
  603. $whereCondition = array(
  604. 'id = ?' => key($settings)
  605. );
  606. Database::update('settings_current', $setData, $whereCondition);
  607. return $resp;
  608. }
  609. /**
  610. * Delete a tab to chamilo's platform
  611. * @param string $key
  612. * @return boolean $resp Transaction response
  613. */
  614. public function deleteTab($key)
  615. {
  616. $t = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  617. $sql = "SELECT *
  618. FROM $t
  619. WHERE variable = 'show_tabs'
  620. AND subkey <> '$key'
  621. AND subkey like 'custom_tab_%'
  622. ";
  623. $resp = $result = Database::query($sql);
  624. $customTabsNum = Database::num_rows($result);
  625. if (!empty($key)) {
  626. $whereCondition = array(
  627. 'variable = ? AND subkey = ?' => array('show_tabs', $key)
  628. );
  629. $resp = Database::delete('settings_current', $whereCondition);
  630. //if there is more than one tab
  631. //re enumerate them
  632. if (!empty($customTabsNum) && $customTabsNum > 0) {
  633. $tabs = Database::store_result($result, 'ASSOC');
  634. $i = 1;
  635. foreach ($tabs as $row) {
  636. $attributes = array(
  637. 'subkey' => 'custom_tab_'.$i
  638. );
  639. $this->updateTab($row['subkey'], $attributes);
  640. $i++;
  641. }
  642. }
  643. }
  644. return $resp;
  645. }
  646. /**
  647. * Update the tabs attributes
  648. * @param string $key
  649. * @param array $attributes
  650. *
  651. * @return boolean
  652. */
  653. public function updateTab($key, $attributes)
  654. {
  655. $whereCondition = array(
  656. 'variable = ? AND subkey = ?' => array('show_tabs', $key)
  657. );
  658. $resp = Database::update('settings_current', $attributes, $whereCondition);
  659. return $resp;
  660. }
  661. /**
  662. * This method shows or hides plugin's tab
  663. * @param boolean $showTab Shows or hides the main menu plugin tab
  664. * @param string $filePath Plugin starter file path
  665. */
  666. public function manageTab($showTab, $filePath = 'index.php')
  667. {
  668. $langString = str_replace('Plugin', '', get_class($this));
  669. $pluginName = strtolower($langString);
  670. $pluginUrl = 'plugin/'.$pluginName.'/'.$filePath;
  671. if ($showTab === 'true') {
  672. $tabAdded = $this->addTab($langString, $pluginUrl);
  673. if ($tabAdded) {
  674. // The page must be refreshed to show the recently created tab
  675. echo "<script>location.href = '".Security::remove_XSS($_SERVER['REQUEST_URI'])."';</script>";
  676. }
  677. } else {
  678. $settingsCurrentTable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  679. $conditions = array(
  680. 'where' => array(
  681. "variable = 'show_tabs' AND title = ? AND comment = ? " => array(
  682. $langString,
  683. $pluginUrl
  684. )
  685. )
  686. );
  687. $result = Database::select('subkey', $settingsCurrentTable, $conditions);
  688. if (!empty($result)) {
  689. $this->deleteTab($result[0]['subkey']);
  690. }
  691. }
  692. }
  693. /**
  694. * @param string $variable
  695. * @return bool
  696. */
  697. public function validateCourseSetting($variable)
  698. {
  699. return true;
  700. }
  701. /**
  702. * @param string $region
  703. * @return string
  704. */
  705. public function renderRegion($region)
  706. {
  707. return '';
  708. }
  709. /**
  710. * Returns true if the plugin is installed, false otherwise
  711. * @return bool True if plugin is installed/enabled, false otherwise
  712. */
  713. public function isEnabled()
  714. {
  715. $settings = api_get_settings_params_simple(
  716. array(
  717. "subkey = ? AND category = ? AND type = ? AND variable = 'status' " => array($this->get_name(), 'Plugins', 'setting')
  718. )
  719. );
  720. if (is_array($settings) && isset($settings['selected_value']) && $settings['selected_value'] == 'installed') {
  721. return true;
  722. }
  723. return false;
  724. }
  725. }