PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/SortMember/inc/config.php

http://wowroster-addons.googlecode.com/
PHP | 323 lines | 201 code | 56 blank | 66 comment | 23 complexity | ea3ac25d78bf475fcc317a2ed5081b6b MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /******************************
  3. * WoWRoster.net Roster
  4. * Copyright 2002-2006
  5. * Licensed under the Creative Commons
  6. * "Attribution-NonCommercial-ShareAlike 2.5" license
  7. *
  8. * Short summary
  9. * http://creativecommons.org/licenses/by-nc-sa/2.5/
  10. *
  11. * Full license information
  12. * http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode
  13. * -----------------------------
  14. *
  15. * $Id: config.php 105 2007-02-25 13:18:55Z PleegWat $
  16. *
  17. ******************************/
  18. if ( !defined('ROSTER_INSTALLED') )
  19. {
  20. exit('Detected invalid access to this file!');
  21. }
  22. class config
  23. {
  24. var $db_values;
  25. var $conf_arrays;
  26. var $tablename;
  27. var $form_start;
  28. var $submit_button;
  29. var $form_end;
  30. /**
  31. * Constructor. We define the config table to work with here.
  32. */
  33. function config( $tablename)
  34. {
  35. global $wordings, $roster_conf;
  36. $this->form_start = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" id=\"config\" onsubmit=\"return confirm('".$wordings[$roster_conf['roster_lang']]['confirm_config_submit']."') && submitonce(this)\">\n";
  37. $this->submit_button = "<input type=\"submit\" value=\"Save Settings\" />\n<input type=\"reset\" name=\"Reset\" value=\"Reset\" onClick=\"return confirm('".$wordings[$roster_conf['roster_lang']]['confirm_config_reset']."')\"/>\n<input type=\"hidden\" name=\"process\" value=\"process\" />\n<br /><br />\n";
  38. $this->form_end = "</form>\n";
  39. $this->tablename = $tablename;
  40. }
  41. /**
  42. * Build the JScript call to select the initial page
  43. *
  44. * @return string $JScript | HTML code for JScript to open default page
  45. */
  46. function writeJScript()
  47. {
  48. $JScript = '<script type="text/javascript">
  49. initializetabcontent("config_tabs")
  50. </script>';
  51. return $JScript;
  52. }
  53. /**
  54. * Build the config page menu
  55. *
  56. * @return string $menu | HTML code for menu/linklist.
  57. * Note: Does not produce the <ul></ul> tags for the list, so you can add your own extra links at the end.
  58. */
  59. function buildConfigMenu()
  60. {
  61. global $wordings, $roster_conf;
  62. $menu = '<!-- Begin Config Menu -->'."\n";
  63. foreach($this->conf_arrays as $type)
  64. {
  65. $menu .= ' <li'.(($type == $this->db_values['master']['startpage']['value']) ? ' class="selected"' : '').'><a href="#" rel="'.$type.'">'.$wordings[$roster_conf['roster_lang']]['admin'][$type].'</a></li>'."\n";
  66. }
  67. $menu .='<!-- End Config Menu -->';
  68. return $menu;
  69. }
  70. /**
  71. * Build the config page body
  72. *
  73. * @return string $html | HTML code for main page body.
  74. */
  75. function buildConfigPage()
  76. {
  77. global $wordings, $roster_conf;
  78. // Build the page
  79. $html = '';
  80. foreach($this->conf_arrays as $type)
  81. {
  82. $i = 0;
  83. $html .= "<div id=\"$type\" style=\"display:none;\">\n".border('sblue','start',$wordings[$roster_conf['roster_lang']]['admin'][$type])."\n<table cellspacing=\"0\" cellpadding=\"0\" class=\"bodyline\">\n";
  84. foreach($this->db_values[$type] as $values)
  85. {
  86. // Here is my nifty auto form generator
  87. // Takes `form_type` from the db and parses it for form type values and labels
  88. // Any un-handled form type will cause this file to just display the current value
  89. // Figure out input type
  90. $input_field = '';
  91. $input_type = explode('{',$values['form_type']);
  92. switch ($input_type[0])
  93. {
  94. case 'text':
  95. $length = explode('|',$input_type[1]);
  96. $input_field = '<input name="config_'.$values['name'].'" type="text" value="'.$values['value'].'" size="'.$length[1].'" maxlength="'.$length[0].'" />';
  97. break;
  98. case 'radio':
  99. $options = explode('|',$input_type[1]);
  100. foreach( $options as $value )
  101. {
  102. $vals = explode('^',$value);
  103. $input_field .= '<label class="'.( $values['value'] == $vals[1] ? 'blue' : 'white' ).'"><input class="checkBox" type="radio" name="config_'.$values['name'].'" value="'.$vals[1].'" '.( $values['value'] == $vals[1] ? 'checked="checked"' : '' ).' />'.$vals[0]."</label>\n";
  104. }
  105. break;
  106. case 'select':
  107. $options = explode('|',$input_type[1]);
  108. $input_field .= '<select name="config_'.$values['name'].'">'."\n";
  109. $select_one = 1;
  110. foreach( $options as $value )
  111. {
  112. $vals = explode('^',$value);
  113. if( $values['value'] == $vals[1] && $select_one )
  114. {
  115. $input_field .= ' <option value="'.$vals[1].'" selected="selected">&gt;'.$vals[0].'&lt;</option>'."\n";
  116. $select_one = 0;
  117. }
  118. else
  119. {
  120. $input_field .= ' <option value="'.$vals[1].'">'.$vals[0].'</option>'."\n";
  121. }
  122. }
  123. $input_field .= '</select>';
  124. break;
  125. case 'function':
  126. $input_field = $input_type[1]();
  127. break;
  128. case 'display':
  129. $input_field = $values['value'];
  130. break;
  131. default:
  132. $input_field = $values['value'];
  133. break;
  134. }
  135. $html .= '
  136. <tr>
  137. <td class="membersRow'.(($i%2)+1).'">'.$this->createTip($values['description'],$values['tooltip'],$values['description']).'</td>
  138. <td class="membersRowRight'.(($i%2)+1).'"><div align="right">'.$input_field.'</div></td>
  139. </tr>';
  140. $i++;
  141. }
  142. $html .= "</table>\n".border('sblue','end')."\n</div>\n";
  143. }
  144. return $html;
  145. }
  146. /**
  147. * Process Data for entry to the database
  148. */
  149. function processData()
  150. {
  151. global $wowdb, $queries;
  152. if (!(array_key_exists('process',$_POST) && ($_POST['process'] == 'process'))) {
  153. return '';
  154. }
  155. $wowdb->reset_values();
  156. // Update only the changed fields
  157. foreach( $_POST as $settingName => $settingValue )
  158. {
  159. if( substr($settingName,0,7) == 'config_' )
  160. {
  161. $settingName = str_replace('config_','',$settingName);
  162. $get_val = "SELECT `config_value` FROM `".$this->tablename."` WHERE `config_name` = '".$settingName."';";
  163. $result = $wowdb->query($get_val)
  164. or die_quietly($wowdb->error(),'Database Error',basename(__FILE__),__LINE__,$get_val);
  165. $config = $wowdb->fetch_assoc($result);
  166. if( $config['config_value'] != $settingValue && $settingName != 'process' )
  167. {
  168. $update_sql[] = "UPDATE `".$this->tablename."` SET `config_value` = '".$wowdb->escape( $settingValue )."' WHERE `config_name` = '".$settingName."';";
  169. }
  170. }
  171. }
  172. // Update DataBase
  173. if( is_array($update_sql) )
  174. {
  175. foreach( $update_sql as $sql )
  176. {
  177. $queries[] = $sql;
  178. $result = $wowdb->query($sql);
  179. if( !$result )
  180. {
  181. return '<span style="color:#0099FF;font-size:11px;">Error saving settings</span><br />MySQL Said:<br /><pre>'.$wowdb->error().'</pre><br />';
  182. }
  183. }
  184. return '<span style="color:#0099FF;font-size:11px;">Settings have been changed</span>';
  185. }
  186. else
  187. {
  188. return '<span style="color:#0099FF;font-size:11px;">No changes have been made</span>';
  189. }
  190. }
  191. /**
  192. * Get roster config data
  193. *
  194. * @return error string on failure
  195. */
  196. function getConfigData ()
  197. {
  198. global $wowdb, $wordings, $roster_conf;
  199. $sql = "SELECT * FROM `".$this->tablename."` ORDER BY `id` ASC;";
  200. // Get the current config values
  201. $results = $wowdb->query($sql);
  202. if( $results && $wowdb->num_rows($results) > 0 )
  203. {
  204. while($row = $wowdb->fetch_assoc($results))
  205. {
  206. $setitem = stripslashes($row['config_type']);
  207. $arrayitem = stripslashes($row['config_name']);
  208. $this->db_values[$setitem][$arrayitem]['id'] = $row['id'];
  209. $this->db_values[$setitem][$arrayitem]['name'] = stripslashes($row['config_name']);
  210. $this->db_values[$setitem][$arrayitem]['config_type'] = stripslashes($row['config_type']);
  211. $this->db_values[$setitem][$arrayitem]['value'] = stripslashes($row['config_value']);
  212. $this->db_values[$setitem][$arrayitem]['form_type'] = stripslashes($row['form_type']);
  213. // Get description and tooltip
  214. $desc_tip = explode('|',$wordings[$roster_conf['roster_lang']]['admin'][$row['config_name']]);
  215. $this->db_values[$setitem][$arrayitem]['description'] = $desc_tip[0];
  216. $db_val_line = '<br /><br /><span style="color:#FFFFFF;font-size:10px;">db name: <span style="color:#0099FF;font-size:10px;">'.$row['config_name'].'</span></span>';
  217. $this->db_values[$setitem][$arrayitem]['tooltip'] = $desc_tip[1].$db_val_line;
  218. }
  219. $this->conf_arrays = explode('|',$this->db_values['master']['config_list']['value']);
  220. return;
  221. }
  222. else
  223. {
  224. return $wowdb->error();
  225. }
  226. }
  227. /**
  228. * Create a tooltip
  229. *
  230. * @param string $disp_text | Text to hover over
  231. * @param string $content | Content in tooltip
  232. * @param string $caption | Text in the caption
  233. * @return string ( Overlib styled tooltip )
  234. */
  235. function createTip( $disp_text , $content , $caption )
  236. {
  237. $content = str_replace("'","\'", $content);
  238. $content = str_replace('"','&quot;', $content);
  239. $caption = str_replace("'","\'", $caption);
  240. $caption = str_replace('"','&quot;', $caption);
  241. $tipsettings = ",WRAP";
  242. if( !empty($caption) )
  243. $caption2 = ",CAPTION,'$caption'";
  244. $tip = "<div style=\"cursor:help;\" onmouseover=\"return overlib('$content'$caption2$tipsettings);\" onmouseout=\"return nd();\">$disp_text</div>";
  245. return $tip;
  246. }
  247. /**
  248. * Applies addslashes() to the provided data
  249. *
  250. * @param mixed $data Array of data or a single string
  251. * @return mixed Array or string of data
  252. */
  253. function slash_global_data(&$data)
  254. {
  255. if ( is_array($data) )
  256. {
  257. foreach ( $data as $k => $v )
  258. {
  259. $data[$k] = ( is_array($v) ) ? slash_global_data($v) : addslashes($v);
  260. }
  261. }
  262. return $data;
  263. }
  264. }
  265. $config = new config($tablename);
  266. ?>