admincp_threadtypes.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_threadtypes.php 36345 2017-01-12 01:55:04Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. $classoptionmenu = array();
  13. $curclassname = '';
  14. foreach(C::t('forum_typeoption')->fetch_all_by_classid(0) as $option) {
  15. if($_GET['classid'] == $option['optionid']) {
  16. $curclassname = $option['title'];
  17. }
  18. $classoptionmenu[] = array($option['title'], "threadtypes&operation=typeoption&classid=$option[optionid]", $_GET['classid'] == $option['optionid']);
  19. }
  20. $mysql_keywords = array( 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASC', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONNECTION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV', 'DOUBLE', 'DROP', 'DUAL', 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FOR', 'FORCE', 'FOREIGN', 'FROM', 'FULLTEXT', 'GOTO', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE', 'IN', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'INTERVAL', 'INTO', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LABEL', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NOT', 'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC', 'ON', 'OPTIMIZE', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RAID0', 'RANGE', 'READ', 'READS', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', 'SCHEMA', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR', 'SET', 'SHOW', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TABLE', 'TERMINATED', 'THEN', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRIGGER', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', 'VARYING', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WRITE', 'X509', 'XOR', 'YEAR_MONTH', 'ZEROFILL', 'ACTION', 'BIT', 'DATE', 'ENUM', 'NO', 'TEXT', 'TIME');
  21. if(!$operation) {
  22. $navlang = 'threadtype_infotypes';
  23. $operation = 'type';
  24. $changetype = 'threadsorts';
  25. if(!submitcheck('typesubmit')) {
  26. $forumsarray = $fidsarray = array();
  27. $query = C::t('forum_forum')->fetch_all_for_threadsorts();
  28. foreach($query as $forum) {
  29. $forum[$changetype] = dunserialize($forum[$changetype]);
  30. if(is_array($forum[$changetype]['types'])) {
  31. foreach($forum[$changetype]['types'] as $typeid => $name) {
  32. $forumsarray[$typeid][] = '<a href="'.ADMINSCRIPT.'?action=forums&operation=edit&fid='.$forum['fid'].'&anchor=threadtypes">'.$forum['name'].'</a>';
  33. $fidsarray[$typeid][] = $forum['fid'];
  34. }
  35. }
  36. }
  37. $threadtypes = '';
  38. $query = C::t('forum_threadtype')->fetch_all_for_order();
  39. foreach($query as $type) {
  40. $tmpstr = "<a href=\"".ADMINSCRIPT."?action=threadtypes&operation=export&sortid=$type[typeid]\" class=\"act nowrap\">$lang[export]</a>";
  41. $threadtypes .= showtablerow('', array('class="td25"', 'class="td28"', 'class="td29"', 'class="td29"', 'title="'.cplang('forums_threadtypes_forums_comment').'"'), array(
  42. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$type[typeid]\">",
  43. "<input type=\"text\" class=\"txt\" size=\"2\" name=\"displayordernew[$type[typeid]]\" value=\"$type[displayorder]\">",
  44. "<input type=\"text\" class=\"txt\" size=\"15\" name=\"namenew[$type[typeid]]\" value=\"".dhtmlspecialchars($type['name'])."\">",
  45. "<input type=\"text\" class=\"txt\" size=\"30\" name=\"descriptionnew[$type[typeid]]\" value=\"$type[description]\">",
  46. is_array($forumsarray[$type['typeid']]) ? '<ul class="lineheight"><li class="left">'.implode(',&nbsp;</li><li class="left"> ', $forumsarray[$type['typeid']])."</li></ul><input type=\"hidden\" name=\"fids[$type[typeid]]\" value=\"".implode(', ', $fidsarray[$type['typeid']])."\">" : '',
  47. "<a href=\"".ADMINSCRIPT."?action=threadtypes&operation=sortdetail&sortid=$type[typeid]\" class=\"act nowrap\">$lang[detail]</a>&nbsp;&nbsp;
  48. <a href=\"".ADMINSCRIPT."?action=threadtypes&operation=sorttemplate&sortid=$type[typeid]\" class=\"act nowrap\">$lang[threadtype_template]</a>",
  49. $tmpstr,
  50. ), TRUE);
  51. }
  52. ?>
  53. <script type="text/JavaScript">
  54. var rowtypedata = [
  55. [
  56. [1, '', 'td25'],
  57. [1, '<input type="text" class="txt" name="newdisplayorder[]" size="2" value="">', 'td28'],
  58. [1, '<input type="text" class="txt" name="newname[]" size="15">', 'td29'],
  59. [1, '<input type="text" class="txt" name="newdescription[]" size="30" value="">', 'td29'],
  60. [2, '']
  61. ],
  62. ];
  63. </script>
  64. <?php
  65. shownav('forum', 'threadtype_infotypes');
  66. showsubmenu('threadtype_infotypes', array(
  67. array('threadtype_infotypes_type', 'threadtypes', 1),
  68. array('threadtype_infotypes_content', 'threadtypes&operation=content', 0),
  69. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu), '', 0)
  70. ));
  71. showformheader("threadtypes&", 'enctype', 'threadtypeform');
  72. showtableheader('');
  73. showsubtitle(array('', 'display_order', cplang('name').' '.cplang('tiny_bbcode_support'), 'description', 'forums_relation', '', ''), 'header', array('', 'width="60"', 'width="110"', 'width="210"', '', 'width="90"', 'width="60"'));
  74. echo $threadtypes;
  75. echo '<tr><td class="td25"></td><td colspan="5"><div>'.'<span class="filebtn"><input type="hidden" name="importtype" value="file" /><input type="file" name="importfile" class="pf" size="1" onchange="uploadthreadtypexml($(\'threadtypeform\'), \''.ADMINSCRIPT.'?action=threadtypes&operation=import\');" /><a class="addtr" href="JavaScript:;">'.$lang['import'].'</a></span>'.'<a href="###" onclick="addrow(this, 0)" class="addtr">'.$lang['threadtype_infotypes_add'].'</a></div></td>';
  76. showsubmit('typesubmit', 'submit', 'del');
  77. showtablefooter();
  78. showformfooter();
  79. } else {
  80. $updatefids = $modifiedtypes = array();
  81. if(is_array($_GET['delete'])) {
  82. if($_GET['delete']) {
  83. C::t('forum_typeoptionvar')->delete_by_sortid($_GET['delete']);
  84. C::t('forum_typevar')->delete($_GET['delete']);
  85. $affected_rows = C::t('forum_threadtype')->delete($_GET['delete']);
  86. }
  87. foreach($_GET['delete'] as $_GET['sortid']) {
  88. C::t('forum_optionvalue')->drop($_GET['sortid']);
  89. }
  90. if($_GET['delete'] && $affected_rows) {
  91. C::t('forum_thread')->update_sortid_by_sortid(0, $_GET['delete']);
  92. foreach($_GET['delete'] as $id) {
  93. if(is_array($_GET['namenew']) && isset($_GET['namenew'][$id])) {
  94. unset($_GET['namenew'][$id]);
  95. }
  96. if(!empty($_GET['fids'][$id])) {
  97. foreach(explode(',', $_GET['fids'][$id]) as $fid) {
  98. if($fid = intval($fid)) {
  99. $updatefids[$fid]['deletedids'][] = intval($id);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. if(is_array($_GET['namenew']) && $_GET['namenew']) {
  107. foreach($_GET['namenew'] as $typeid => $val) {
  108. $_GET['descriptionnew'] = is_array($_GET['descriptionnew']) ? $_GET['descriptionnew'] : array();
  109. $data = array(
  110. 'name' => trim($_GET['namenew'][$typeid]),
  111. 'description' => dhtmlspecialchars(trim($_GET['descriptionnew'][$typeid])),
  112. 'displayorder' => intval($_GET['displayordernew'][$typeid]),
  113. 'special' => 1,
  114. );
  115. $affected_rows = C::t('forum_threadtype')->update($typeid, $data);
  116. if($affected_rows) {
  117. $modifiedtypes[] = $typeid;
  118. }
  119. }
  120. if($modifiedtypes = array_unique($modifiedtypes)) {
  121. foreach($modifiedtypes as $id) {
  122. if(!empty($_GET['fids'][$id])) {
  123. foreach(explode(',', $_GET['fids'][$id]) as $fid) {
  124. if($fid = intval($fid)) {
  125. $updatefids[$fid]['modifiedids'][] = $id;
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. if($updatefids) {
  133. $query = C::t('forum_forum')->fetch_all_info_by_fids(array_keys($updatefids));
  134. foreach($query as $forum) {
  135. if($forum[$changetype] == '') continue;
  136. $fid = $forum['fid'];
  137. $forum[$changetype] = dunserialize($forum[$changetype]);
  138. if($updatefids[$fid]['deletedids']) {
  139. foreach($updatefids[$fid]['deletedids'] as $id) {
  140. unset($forum[$changetype]['types'][$id], $forum[$changetype]['flat'][$id], $forum[$changetype]['selectbox'][$id]);
  141. }
  142. }
  143. if($updatefids[$fid]['modifiedids']) {
  144. foreach($updatefids[$fid]['modifiedids'] as $id) {
  145. if(isset($forum[$changetype]['types'][$id])) {
  146. $_GET['namenew'][$id] = trim(strip_tags($_GET['namenew'][$id]));
  147. $forum[$changetype]['types'][$id] = $_GET['namenew'][$id];
  148. if(isset($forum[$changetype]['selectbox'][$id])) {
  149. $forum[$changetype]['selectbox'][$id] = $_GET['namenew'][$id];
  150. } else {
  151. $forum[$changetype]['flat'][$id] = $_GET['namenew'][$id];
  152. }
  153. }
  154. }
  155. }
  156. C::t('forum_forumfield')->update($fid, array($changetype => serialize($forum[$changetype])));
  157. }
  158. }
  159. if(is_array($_GET['newname'])) {
  160. foreach($_GET['newname'] as $key => $value) {
  161. if($newname1 = trim(strip_tags($value))) {
  162. if(C::t('forum_threadtype')->checkname($newname1)) {
  163. cpmsg('forums_threadtypes_duplicate', '', 'error');
  164. }
  165. $data = array(
  166. 'name' => $newname1,
  167. 'description' => dhtmlspecialchars(trim($_GET['newdescription'][$key])),
  168. 'displayorder' => $_GET['newdisplayorder'][$key],
  169. 'special' => 1,
  170. );
  171. C::t('forum_threadtype')->insert($data);
  172. }
  173. }
  174. }
  175. cpmsg('forums_threadtypes_succeed', 'action=threadtypes', 'succeed');
  176. }
  177. } elseif($operation == 'typeoption') {
  178. if(!submitcheck('typeoptionsubmit')) {
  179. if($_GET['classid']) {
  180. $typetitle = C::t('forum_typeoption')->fetch($_GET['classid']);
  181. if(!$typetitle['title']) {
  182. cpmsg('threadtype_infotypes_noexist', 'action=threadtypes', 'error');
  183. }
  184. $typeoptions = '';
  185. foreach(C::t('forum_typeoption')->fetch_all_by_classid($_GET['classid']) as $option) {
  186. $option['type'] = $lang['threadtype_edit_vars_type_'. $option['type']];
  187. $typeoptions .= showtablerow('', array('class="td25"', 'class="td28"'), array(
  188. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$option[optionid]\">",
  189. "<input type=\"text\" class=\"txt\" size=\"2\" name=\"displayorder[$option[optionid]]\" value=\"$option[displayorder]\">",
  190. "<input type=\"text\" class=\"txt\" size=\"15\" name=\"title[$option[optionid]]\" value=\"".dhtmlspecialchars($option['title'])."\">",
  191. "$option[identifier]<input type=\"hidden\" name=\"identifier[$option[optionid]]\" value=\"$option[identifier]\">",
  192. $option['type'],
  193. "<a href=\"".ADMINSCRIPT."?action=threadtypes&operation=optiondetail&optionid=$option[optionid]\" class=\"act\">$lang[detail]</a>"
  194. ), TRUE);
  195. }
  196. }
  197. echo <<<EOT
  198. <script type="text/JavaScript">
  199. var rowtypedata = [
  200. [
  201. [1, '', 'td25'],
  202. [1, '<input type="text" class="txt" size="2" name="newdisplayorder[]" value="0">', 'td28'],
  203. [1, '<input type="text" class="txt" size="15" name="newtitle[]">'],
  204. [1, '<input type="text" class="txt" size="15" name="newidentifier[]">'],
  205. [1, '<select name="newtype[]"><option value="number">$lang[threadtype_edit_vars_type_number]</option><option value="text" selected>$lang[threadtype_edit_vars_type_text]</option><option value="textarea">$lang[threadtype_edit_vars_type_textarea]</option><option value="radio">$lang[threadtype_edit_vars_type_radio]</option><option value="checkbox">$lang[threadtype_edit_vars_type_checkbox]</option><option value="select">$lang[threadtype_edit_vars_type_select]</option><option value="calendar">$lang[threadtype_edit_vars_type_calendar]</option><option value="email">$lang[threadtype_edit_vars_type_email]</option><option value="image">$lang[threadtype_edit_vars_type_image]</option><option value="url">$lang[threadtype_edit_vars_type_url]</option><option value="range">$lang[threadtype_edit_vars_type_range]</option></select>'],
  206. [1, '']
  207. ],
  208. ];
  209. </script>
  210. EOT;
  211. shownav('forum', 'threadtype_infotypes');
  212. showsubmenu('threadtype_infotypes', array(
  213. array('threadtype_infotypes_type', 'threadtypes', 0),
  214. array('threadtype_infotypes_content', 'threadtypes&operation=content', 0),
  215. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu), 1)
  216. ));
  217. showformheader("threadtypes&operation=typeoption&typeid={$_GET['typeid']}");
  218. showhiddenfields(array('classid' => $_GET['classid']));
  219. showtableheader();
  220. showsubtitle(array('', 'display_order', 'name', 'threadtype_variable', 'threadtype_type', ''));
  221. echo $typeoptions;
  222. echo '<tr><td></td><td colspan="5"><div><a href="###" onclick="addrow(this, 0)" class="addtr">'.$lang['threadtype_infotypes_add_option'].'</a></div></td></tr>';
  223. showsubmit('typeoptionsubmit', 'submit', 'del');
  224. showtablefooter();
  225. showformfooter();
  226. } else {
  227. if($ids = dimplode($_GET['delete'])) {
  228. C::t('forum_typeoption')->delete($_GET['delete']);
  229. C::t('forum_typevar')->delete(null, $_GET['delete']);
  230. }
  231. if(is_array($_GET['title'])) {
  232. foreach($_GET['title'] as $id => $val) {
  233. if(in_array(strtoupper($_GET['identifier'][$id]), $mysql_keywords)) {
  234. continue;
  235. }
  236. C::t('forum_typeoption')->update($id, array(
  237. 'displayorder' => $_GET['displayorder'][$id],
  238. 'title' => $_GET['title'][$id],
  239. 'identifier' => $_GET['identifier'][$id],
  240. ));
  241. }
  242. }
  243. if(is_array($_GET['newtitle'])) {
  244. foreach($_GET['newtitle'] as $key => $value) {
  245. $newtitle1 = dhtmlspecialchars(trim($value));
  246. $newidentifier1 = trim($_GET['newidentifier'][$key]);
  247. if($newtitle1 && $newidentifier1) {
  248. if(in_array(strtoupper($newidentifier1), $mysql_keywords)) {
  249. cpmsg('threadtype_infotypes_optionvariable_iskeyword', '', 'error');
  250. }
  251. if(C::t('forum_typeoption')->fetch_all_by_identifier($newidentifier1, 0, 1) || strlen($newidentifier1) > 40 || !ispluginkey($newidentifier1)) {
  252. cpmsg('threadtype_infotypes_optionvariable_invalid', '', 'error');
  253. }
  254. $data = array(
  255. 'classid' => $_GET['classid'],
  256. 'displayorder' => $_GET['newdisplayorder'][$key],
  257. 'title' => $newtitle1,
  258. 'identifier' => $newidentifier1,
  259. 'type' => $_GET['newtype'][$key],
  260. );
  261. C::t('forum_typeoption')->insert($data);
  262. } elseif($newtitle1 && !$newidentifier1) {
  263. cpmsg('threadtype_infotypes_option_invalid', 'action=threadtypes&operation=typeoption&classid='.$_GET['classid'], 'error');
  264. }
  265. }
  266. }
  267. updatecache('threadsorts');
  268. cpmsg('threadtype_infotypes_succeed', 'action=threadtypes&operation=typeoption&classid='.$_GET['classid'], 'succeed');
  269. }
  270. } elseif($operation == 'optiondetail') {
  271. $option = C::t('forum_typeoption')->fetch($_GET['optionid']);
  272. if(!$option) {
  273. cpmsg('typeoption_not_found', '', 'error');
  274. }
  275. if(!submitcheck('editsubmit')) {
  276. shownav('forum', 'threadtype_infotypes');
  277. showsubmenu('threadtype_infotypes', array(
  278. array('threadtype_infotypes_type', 'threadtypes', 0),
  279. array('threadtype_infotypes_content', 'threadtypes&operation=content', 0),
  280. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu), '', 1)
  281. ));
  282. $typeselect = '<select name="typenew" onchange="var styles, key;styles=new Array(\'number\',\'text\',\'radio\', \'checkbox\', \'textarea\', \'select\', \'image\', \'calendar\', \'range\', \'info\'); for(key in styles) {var obj=$(\'style_\'+styles[key]); if(obj) { obj.style.display=styles[key]==this.options[this.selectedIndex].value?\'\':\'none\';}}">';
  283. foreach(array('number', 'text', 'radio', 'checkbox', 'textarea', 'select', 'calendar', 'email', 'url', 'image', 'range') as $type) {
  284. $typeselect .= '<option value="'.$type.'" '.($option['type'] == $type ? 'selected' : '').'>'.$lang['threadtype_edit_vars_type_'.$type].'</option>';
  285. }
  286. $typeselect .= '</select>';
  287. $option['rules'] = dunserialize($option['rules']);
  288. $option['protect'] = dunserialize($option['protect']);
  289. $groups = $forums = array();
  290. foreach(C::t('common_usergroup')->range() as $group) {
  291. $groups[] = array($group['groupid'], $group['grouptitle']);
  292. }
  293. $verifys = array();
  294. if($_G['setting']['verify']['enabled']) {
  295. foreach($_G['setting']['verify'] as $key => $verify) {
  296. if($verify['available'] == 1) {
  297. $verifys[] = array($key, $verify['title']);
  298. }
  299. }
  300. }
  301. foreach(C::t('common_member_profile_setting')->fetch_all_by_available_formtype(1, 'text') as $result) {
  302. $threadtype_profile = !$threadtype_profile ? "<select id='rules[text][profile]' name='rules[text][profile]'><option value=''></option>" : $threadtype_profile."<option value='{$result[fieldid]}' ".($option['rules']['profile'] == $result['fieldid'] ? "selected='selected'" : '').">{$result[title]}</option>";
  303. }
  304. $threadtype_profile .= "</select>";
  305. showformheader("threadtypes&operation=optiondetail&optionid=$_GET[optionid]");
  306. showtableheader();
  307. showtitle('threadtype_infotypes_option_config');
  308. showsetting('name', 'titlenew', $option['title'], 'text');
  309. showsetting('threadtype_variable', 'identifiernew', $option['identifier'], 'text');
  310. showsetting('type', '', '', $typeselect);
  311. showsetting('threadtype_edit_desc', 'descriptionnew', $option['description'], 'textarea');
  312. showsetting('threadtype_unit', 'unitnew', $option['unit'], 'text');
  313. showsetting('threadtype_expiration', 'expirationnew', $option['expiration'], 'radio');
  314. if(in_array($option['type'], array('calendar', 'number', 'text', 'email', 'textarea'))) {
  315. showsetting('threadtype_protect', 'protectnew[status]', $option['protect']['status'], 'radio', 0, 1);
  316. showsetting('threadtype_protect_mode', array('protectnew[mode]', array(
  317. array(1, $lang['threadtype_protect_mode_pic']),
  318. array(2, $lang['threadtype_protect_mode_html'])
  319. )), $option['protect']['mode'], 'mradio');
  320. showsetting('threadtype_protect_usergroup', array('protectnew[usergroup][]', $groups), explode("\t", $option['protect']['usergroup']), 'mselect');
  321. $verifys && showsetting('threadtype_protect_verify', array('protectnew[verify][]', $verifys), explode("\t", $option['protect']['verify']), 'mselect');
  322. showsetting('threadtype_protect_permprompt', 'permpromptnew', $option['permprompt'], 'textarea');
  323. }
  324. showtagheader('tbody', "style_calendar", $option['type'] == 'calendar');
  325. showtitle('threadtype_edit_vars_type_calendar');
  326. showsetting('threadtype_edit_inputsize', 'rules[calendar][inputsize]', $option['rules']['inputsize'], 'text');
  327. showtagfooter('tbody');
  328. showtagheader('tbody', "style_number", $option['type'] == 'number');
  329. showtitle('threadtype_edit_vars_type_number');
  330. showsetting('threadtype_edit_maxnum', 'rules[number][maxnum]', $option['rules']['maxnum'], 'text');
  331. showsetting('threadtype_edit_minnum', 'rules[number][minnum]', $option['rules']['minnum'], 'text');
  332. showsetting('threadtype_edit_inputsize', 'rules[number][inputsize]', $option['rules']['inputsize'], 'text');
  333. showsetting('threadtype_defaultvalue', 'rules[number][defaultvalue]', $option['rules']['defaultvalue'], 'text');
  334. showtagfooter('tbody');
  335. showtagheader('tbody', "style_text", $option['type'] == 'text');
  336. showtitle('threadtype_edit_vars_type_text');
  337. showsetting('threadtype_edit_textmax', 'rules[text][maxlength]', $option['rules']['maxlength'], 'text');
  338. showsetting('threadtype_edit_inputsize', 'rules[text][inputsize]', $option['rules']['inputsize'], 'text');
  339. showsetting('threadtype_edit_profile', '', '', $threadtype_profile);
  340. showsetting('threadtype_defaultvalue', 'rules[text][defaultvalue]', $option['rules']['defaultvalue'], 'text');
  341. showtagfooter('tbody');
  342. showtagheader('tbody', "style_textarea", $option['type'] == 'textarea');
  343. showtitle('threadtype_edit_vars_type_textarea');
  344. showsetting('threadtype_edit_textmax', 'rules[textarea][maxlength]', $option['rules']['maxlength'], 'text');
  345. showsetting('threadtype_edit_colsize', 'rules[textarea][colsize]', $option['rules']['colsize'], 'text');
  346. showsetting('threadtype_edit_rowsize', 'rules[textarea][rowsize]', $option['rules']['rowsize'], 'text');
  347. showsetting('threadtype_defaultvalue', 'rules[textarea][defaultvalue]', $option['rules']['defaultvalue'], 'text');
  348. showtagfooter('tbody');
  349. showtagheader('tbody', "style_select", $option['type'] == 'select');
  350. showtitle('threadtype_edit_vars_type_select');
  351. showsetting('threadtype_edit_select_choices', 'rules[select][choices]', $option['rules']['choices'], 'textarea');
  352. showsetting('threadtype_edit_inputsize', 'rules[select][inputsize]', $option['rules']['inputsize'], 'text');
  353. showtagfooter('tbody');
  354. showtagheader('tbody', "style_radio", $option['type'] == 'radio');
  355. showtitle('threadtype_edit_vars_type_radio');
  356. showsetting('threadtype_edit_choices', 'rules[radio][choices]', $option['rules']['choices'], 'textarea');
  357. showtagfooter('tbody');
  358. showtagheader('tbody', "style_checkbox", $option['type'] == 'checkbox');
  359. showtitle('threadtype_edit_vars_type_checkbox');
  360. showsetting('threadtype_edit_choices', 'rules[checkbox][choices]', $option['rules']['choices'], 'textarea');
  361. showtagfooter('tbody');
  362. showtagheader('tbody', "style_image", $option['type'] == 'image');
  363. showtitle('threadtype_edit_vars_type_image');
  364. showsetting('threadtype_edit_images_weight', 'rules[image][maxwidth]', $option['rules']['maxwidth'], 'text');
  365. showsetting('threadtype_edit_images_height', 'rules[image][maxheight]', $option['rules']['maxheight'], 'text');
  366. showsetting('threadtype_edit_inputsize', 'rules[image][inputsize]', $option['rules']['inputsize'], 'text');
  367. showtagfooter('tbody');
  368. showtagheader('tbody', "style_range", $option['type'] == 'range');
  369. showtitle('threadtype_edit_vars_type_range');
  370. showsetting('threadtype_edit_maxnum', 'rules[range][maxnum]', $option['rules']['maxnum'], 'text');
  371. showsetting('threadtype_edit_minnum', 'rules[range][minnum]', $option['rules']['minnum'], 'text');
  372. showsetting('threadtype_edit_inputsize', 'rules[range][inputsize]', $option['rules']['inputsize'], 'text');
  373. showsetting('threadtype_edit_searchtxt', 'rules[range][searchtxt]', $option['rules']['searchtxt'], 'text');
  374. showtagfooter('tbody');
  375. showsubmit('editsubmit');
  376. showtablefooter();
  377. showformfooter();
  378. } else {
  379. $titlenew = trim($_GET['titlenew']);
  380. $_GET['identifiernew'] = trim($_GET['identifiernew']);
  381. if(!$titlenew || !$_GET['identifiernew']) {
  382. cpmsg('threadtype_infotypes_option_invalid', '', 'error');
  383. }
  384. if(in_array(strtoupper($_GET['identifiernew']), $mysql_keywords)) {
  385. cpmsg('threadtype_infotypes_optionvariable_iskeyword', '', 'error');
  386. }
  387. if(C::t('forum_typeoption')->fetch_all_by_identifier($_GET['identifiernew'], 0, 1, $_GET['optionid']) || strlen($_GET['identifiernew']) > 40 || !ispluginkey($_GET['identifiernew'])) {
  388. cpmsg('threadtype_infotypes_optionvariable_invalid', '', 'error');
  389. }
  390. $_GET['protectnew']['usergroup'] = $_GET['protectnew']['usergroup'] ? implode("\t", $_GET['protectnew']['usergroup']) : '';
  391. $_GET['protectnew']['verify'] = $_GET['protectnew']['verify'] ? implode("\t", $_GET['protectnew']['verify']) : '';
  392. C::t('forum_typeoption')->update($_GET['optionid'], array(
  393. 'title' => $titlenew,
  394. 'description' => $_GET['descriptionnew'],
  395. 'identifier' => $_GET['identifiernew'],
  396. 'type' => $_GET['typenew'],
  397. 'unit' => $_GET['unitnew'],
  398. 'expiration' => $_GET['expirationnew'],
  399. 'protect' => serialize($_GET['protectnew']),
  400. 'rules' => serialize($_GET['rules'][$_GET['typenew']]),
  401. 'permprompt' => $_GET['permpromptnew'],
  402. ));
  403. updatecache('threadsorts');
  404. cpmsg('threadtype_infotypes_option_succeed', 'action=threadtypes&operation=typeoption&classid='.$option['classid'], 'succeed');
  405. }
  406. } elseif($operation == 'sortdetail') {
  407. if(!submitcheck('sortdetailsubmit')) {
  408. $threadtype = C::t('forum_threadtype')->fetch($_GET['sortid']);
  409. $threadtype['modelid'] = isset($_GET['modelid']) ? intval($_GET['modelid']) : $threadtype['modelid'];
  410. $sortoptions = $jsoptionids = '';
  411. $showoption = array();
  412. $typevararr = C::t('forum_typevar')->fetch_all_by_sortid($_GET['sortid'], 'ASC');
  413. $typeoptionarr = C::t('forum_typeoption')->fetch_all(array_keys($typevararr));
  414. foreach($typevararr as $option) {
  415. $option['title'] = $typeoptionarr[$option['optionid']]['title'];
  416. $option['type'] = $typeoptionarr[$option['optionid']]['type'];
  417. $option['identifier'] = $typeoptionarr[$option['optionid']]['identifier'];
  418. $jsoptionids .= "optionids.push($option[optionid]);\r\n";
  419. $optiontitle[$option['identifier']] = $option['title'];
  420. $showoption[$option['optionid']]['optionid'] = $option['optionid'];
  421. $showoption[$option['optionid']]['title'] = $option['title'];
  422. $showoption[$option['optionid']]['type'] = $lang['threadtype_edit_vars_type_'. $option['type']];
  423. $showoption[$option['optionid']]['identifier'] = $option['identifier'];
  424. $showoption[$option['optionid']]['displayorder'] = $option['displayorder'];
  425. $showoption[$option['optionid']]['available'] = $option['available'];
  426. $showoption[$option['optionid']]['required'] = $option['required'];
  427. $showoption[$option['optionid']]['unchangeable'] = $option['unchangeable'];
  428. $showoption[$option['optionid']]['search'] = $option['search'];
  429. $showoption[$option['optionid']]['subjectshow'] = $option['subjectshow'];
  430. }
  431. unset($typevararr, $typeoptionarr);
  432. if($existoption && is_array($existoption)) {
  433. $optionids = array();
  434. foreach($existoption as $optionid => $val) {
  435. $optionids[] = $optionid;
  436. }
  437. foreach(C::t('forum_typeoption')->fetch_all($optionids) as $option) {
  438. $showoption[$option['optionid']]['optionid'] = $option['optionid'];
  439. $showoption[$option['optionid']]['title'] = $option['title'];
  440. $showoption[$option['optionid']]['type'] = $lang['threadtype_edit_vars_type_'. $option['type']];
  441. $showoption[$option['optionid']]['identifier'] = $option['identifier'];
  442. $showoption[$option['optionid']]['required'] = $existoption[$option['optionid']];
  443. $showoption[$option['optionid']]['available'] = 1;
  444. $showoption[$option['optionid']]['unchangeable'] = 0;
  445. $showoption[$option['optionid']]['model'] = 1;
  446. }
  447. }
  448. $searchtitle = $searchvalue = $searchunit = array();
  449. foreach($showoption as $optionid => $option) {
  450. $sortoptions .= showtablerow('id="optionid'.$optionid.'"', array('class="td25"', 'class="td28 td23"'), array(
  451. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$option[optionid]\">",
  452. "<input type=\"text\" class=\"txt\" size=\"2\" name=\"displayorder[$option[optionid]]\" value=\"$option[displayorder]\">",
  453. "<input class=\"checkbox\" type=\"checkbox\" name=\"available[$option[optionid]]\" value=\"1\" ".($option['available'] ? 'checked' : '')." ".($option['model'] ? 'disabled' : '').">",
  454. dhtmlspecialchars($option['title']),
  455. $option['type'],
  456. "<input class=\"checkbox\" type=\"checkbox\" name=\"required[$option[optionid]]\" value=\"1\" ".($option['required'] ? 'checked' : '')." ".($option['model'] ? 'disabled' : '').">",
  457. "<input class=\"checkbox\" type=\"checkbox\" name=\"unchangeable[$option[optionid]]\" value=\"1\" ".($option['unchangeable'] ? 'checked' : '').">",
  458. "<input class=\"checkbox\" type=\"checkbox\" name=\"search[$option[optionid]][form]\" value=\"1\" ".(getstatus($option['search'], 1) == 1 ? 'checked' : '').">",
  459. "<input class=\"checkbox\" type=\"checkbox\" name=\"search[$option[optionid]][font]\" value=\"1\" ".(getstatus($option['search'], 2) == 1 ? 'checked' : '').">",
  460. "<input class=\"checkbox\" type=\"checkbox\" name=\"subjectshow[$option[optionid]]\" value=\"1\" ".($option['subjectshow'] ? 'checked' : '').">",
  461. "<a href=\"".ADMINSCRIPT."?action=threadtypes&operation=optiondetail&optionid=$option[optionid]\" class=\"act\" target=\"_blank\">".$lang['edit']."</a>"
  462. ), TRUE);
  463. $searchtitle[] = '/{('.$option['identifier'].')}/e';
  464. $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  465. $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  466. }
  467. shownav('forum', 'threadtype_infotypes');
  468. showsubmenu('threadtype_infotypes', array(
  469. array('threadtype_infotypes_type', 'threadtypes', 1),
  470. array('threadtype_infotypes_content', 'threadtypes&operation=content', 0),
  471. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu), '', 0)
  472. ));
  473. showsubmenu('forums_edit_threadsorts');
  474. showtips('forums_edit_threadsorts_tips');
  475. showformheader("threadtypes&operation=sortdetail&sortid={$_GET['sortid']}");
  476. showtableheader('threadtype_infotypes_validity', 'nobottom');
  477. showsetting('threadtype_infotypes_validity', 'typeexpiration', $threadtype['expiration'], 'radio');
  478. showtablefooter();
  479. showtableheader("$threadtype[name] - $lang[threadtype_infotypes_add_option]", 'noborder fixpadding');
  480. showtablerow('', 'id="classlist"', '');
  481. showtablerow('', 'id="optionlist"', '');
  482. showtablefooter();
  483. showtableheader("$threadtype[name] - $lang[threadtype_infotypes_exist_option]", 'noborder fixpadding', 'id="sortlist"');
  484. showsubtitle(array('<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(\'prefix\', this.form,\'delete\')" /><label for="chkall">'.cplang('del').'</label>', 'display_order', 'available', 'name', 'type', 'required', 'unchangeable', 'threadtype_infotypes_formsearch', 'threadtype_infotypes_fontsearch', 'threadtype_infotypes_show', ''));
  485. echo $sortoptions;
  486. showtablefooter();
  487. ?>
  488. <input type="submit" class="btn" name="sortdetailsubmit" value="<?php echo $lang['submit'];?>">
  489. </form>
  490. <script type="text/JavaScript">
  491. var optionids = new Array();
  492. <?php echo $jsoptionids;?>
  493. function checkedbox() {
  494. var tags = $('optionlist').getElementsByTagName('input');
  495. for(var i=0; i<tags.length; i++) {
  496. if(in_array(tags[i].value, optionids)) {
  497. tags[i].checked = true;
  498. }
  499. }
  500. }
  501. function insertoption(optionid) {
  502. var x = new Ajax();
  503. x.optionid = optionid;
  504. x.get('<?php echo ADMINSCRIPT;?>?action=threadtypes&operation=sortlist&inajax=1&optionid=' + optionid, function(s, x) {
  505. if(!in_array(x.optionid, optionids)) {
  506. var div = document.createElement('div');
  507. div.style.display = 'none';
  508. $('append_parent').appendChild(div);
  509. div.innerHTML = '<table>' + s + '</table>';
  510. var tr = div.getElementsByTagName('tr');
  511. var trs = $('sortlist').getElementsByTagName('tr');
  512. tr[0].id = 'optionid' + optionid;
  513. trs[trs.length - 1].parentNode.appendChild(tr[0]);
  514. $('append_parent').removeChild(div);
  515. optionids.push(x.optionid);
  516. } else {
  517. $('optionid' + x.optionid).parentNode.removeChild($('optionid' + x.optionid));
  518. for(var i=0; i<optionids.length; i++) {
  519. if(optionids[i] == x.optionid) {
  520. optionids[i] = 0;
  521. }
  522. }
  523. }
  524. });
  525. }
  526. </script>
  527. <script type="text/JavaScript">ajaxget('<?php echo ADMINSCRIPT;?>?action=threadtypes&operation=classlist', 'classlist');</script>
  528. <script type="text/JavaScript">ajaxget('<?php echo ADMINSCRIPT;?>?action=threadtypes&operation=optionlist&sortid=<?php echo $_GET['sortid'];?>', 'optionlist', '', '', '', checkedbox);</script>
  529. <?php
  530. } else {
  531. $threadtype = C::t('forum_threadtype')->fetch($_GET['sortid']);
  532. if($_GET['typeexpiration'] != $threadtype['expiration']) {
  533. $query = C::t('forum_forum')->fetch_all_for_threadsorts();
  534. $fidsarray = array();
  535. foreach($query as $forum) {
  536. $forum['threadsorts'] = dunserialize($forum['threadsorts']);
  537. if(is_array($forum['threadsorts']['types'])) {
  538. foreach($forum['threadsorts']['types'] as $typeid => $name) {
  539. $typeid == $_GET['sortid'] && $fidsarray[$forum['fid']] = $forum['threadsorts'];
  540. }
  541. }
  542. }
  543. if($fidsarray) {
  544. foreach($fidsarray as $changefid => $forumthreadsorts) {
  545. $forumthreadsorts['expiration'][$_GET['sortid']] = $_GET['typeexpiration'];
  546. C::t('forum_forumfield')->update($changefid, array('threadsorts' => serialize($forumthreadsorts)));
  547. }
  548. }
  549. }
  550. C::t('forum_threadtype')->update($_GET['sortid'], array('special' => 1, 'modelid' => $_GET['modelid'], 'expiration' => $_GET['typeexpiration']));
  551. if(submitcheck('sortdetailsubmit')) {
  552. $orgoption = $orgoptions = $addoption = array();
  553. foreach(C::t('forum_typevar')->fetch_all_by_sortid($_GET['sortid']) as $orgoption) {
  554. $orgoptions[] = $orgoption['optionid'];
  555. }
  556. $addoption = $addoption ? (array)$addoption + (array)$_GET['displayorder'] : (array)$_GET['displayorder'];
  557. @$newoptions = array_keys($addoption);
  558. if(empty($addoption)) {
  559. cpmsg('threadtype_infotypes_invalid', '', 'error');
  560. }
  561. @$delete = array_merge((array)$_GET['delete'], array_diff($orgoptions, $newoptions));
  562. if($delete) {
  563. if($ids = dimplode($delete)) {
  564. C::t('forum_typevar')->delete($_GET['sortid'], $delete);
  565. }
  566. foreach($delete as $id) {
  567. unset($addoption[$id]);
  568. }
  569. }
  570. $insertoptionid = $indexoption = array();
  571. $create_table_sql = $separator = $create_tableoption_sql = '';
  572. if(is_array($addoption) && !empty($addoption)) {
  573. foreach(C::t('forum_typeoption')->fetch_all(array_keys($addoption)) as $option) {
  574. $insertoptionid[$option['optionid']]['type'] = $option['type'];
  575. $insertoptionid[$option['optionid']]['identifier'] = $option['identifier'];
  576. }
  577. if(!C::t('forum_optionvalue')->showcolumns($_GET['sortid'])) {
  578. $fields = '';
  579. foreach($addoption as $optionid => $option) {
  580. $identifier = $insertoptionid[$optionid]['identifier'];
  581. if($identifier) {
  582. if(in_array($insertoptionid[$optionid]['type'], array('radio'))) {
  583. $create_tableoption_sql .= "$separator$identifier smallint(6) UNSIGNED NOT NULL DEFAULT '0'";
  584. } elseif(in_array($insertoptionid[$optionid]['type'], array('number', 'range'))) {
  585. $create_tableoption_sql .= "$separator$identifier int(10) UNSIGNED NOT NULL DEFAULT '0'";
  586. } elseif($insertoptionid[$optionid]['type'] == 'select') {
  587. $create_tableoption_sql .= "$separator$identifier varchar(50) NOT NULL";
  588. } else {
  589. $create_tableoption_sql .= "$separator$identifier mediumtext NOT NULL";
  590. }
  591. $separator = ' ,';
  592. if(in_array($insertoptionid[$optionid]['type'], array('radio', 'select', 'number'))) {
  593. $indexoption[] = $identifier;
  594. }
  595. }
  596. }
  597. $fields .= ($create_tableoption_sql ? $create_tableoption_sql.',' : '')."tid mediumint(8) UNSIGNED NOT NULL DEFAULT '0',fid smallint(6) UNSIGNED NOT NULL DEFAULT '0',dateline int(10) UNSIGNED NOT NULL DEFAULT '0',expiration int(10) UNSIGNED NOT NULL DEFAULT '0',";
  598. $fields .= "KEY (fid), KEY(dateline)";
  599. if($indexoption) {
  600. foreach($indexoption as $index) {
  601. $fields .= "$separator KEY $index ($index)";
  602. $separator = ' ,';
  603. }
  604. }
  605. $dbcharset = $_G['config']['db'][1]['dbcharset'];
  606. $dbcharset = empty($dbcharset) ? str_replace('-','',CHARSET) : $dbcharset;
  607. C::t('forum_optionvalue')->create($_GET['sortid'], $fields, $dbcharset);
  608. } else {
  609. $tables = C::t('forum_optionvalue')->showcolumns($_GET['sortid']);
  610. foreach($addoption as $optionid => $option) {
  611. $identifier = $insertoptionid[$optionid]['identifier'];
  612. if(!$tables[$identifier]) {
  613. $fieldname = $identifier;
  614. if(in_array($insertoptionid[$optionid]['type'], array('radio'))) {
  615. $fieldtype = 'smallint(6) UNSIGNED NOT NULL DEFAULT \'0\'';
  616. } elseif(in_array($insertoptionid[$optionid]['type'], array('number', 'range'))) {
  617. $fieldtype = 'int(10) UNSIGNED NOT NULL DEFAULT \'0\'';
  618. } elseif($insertoptionid[$optionid]['type'] == 'select') {
  619. $fieldtype = 'varchar(50) NOT NULL';
  620. } else {
  621. $fieldtype = 'mediumtext NOT NULL';
  622. }
  623. C::t('forum_optionvalue')->alter($_GET['sortid'], "ADD $fieldname $fieldtype");
  624. if(in_array($insertoptionid[$optionid]['type'], array('radio', 'select', 'number'))) {
  625. C::t('forum_optionvalue')->alter($_GET['sortid'], "ADD INDEX ($fieldname)");
  626. }
  627. }
  628. }
  629. }
  630. foreach($addoption as $id => $val) {
  631. $optionid = C::t('forum_typeoption')->fetch($id);
  632. if($optionid) {
  633. $data = array(
  634. 'sortid' => $_GET['sortid'],
  635. 'optionid' => $id,
  636. 'available' => 1,
  637. 'required' => intval($val),
  638. );
  639. C::t('forum_typevar')->insert($data, 0, 0, 1);
  640. $search_bit = 0;
  641. foreach($_GET['search'][$id] AS $key => $val) {
  642. if($val == 1) {
  643. if($key == 'font') {
  644. $search_bit = setstatus(2, 1, $search_bit);
  645. } elseif($key == 'form') {
  646. $search_bit = setstatus(1, 1, $search_bit);
  647. }
  648. }
  649. }
  650. C::t('forum_typevar')->update($_GET['sortid'], $id, array(
  651. 'displayorder' => $_GET['displayorder'][$id],
  652. 'available' => $_GET['available'][$id],
  653. 'required' => $_GET['required'][$id],
  654. 'unchangeable' => $_GET['unchangeable'][$id],
  655. 'search' => $search_bit,
  656. 'subjectshow' => $_GET['subjectshow'][$id],
  657. ));
  658. } else {
  659. C::t('forum_typevar')->delete($_GET['sortid'], $id);
  660. }
  661. }
  662. }
  663. updatecache('threadsorts');
  664. cpmsg('threadtype_infotypes_succeed', 'action=threadtypes&operation=sortdetail&sortid='.$_GET['sortid'], 'succeed');
  665. }
  666. }
  667. } elseif($operation == 'sorttemplate') {
  668. if(!submitcheck('sorttemplatesubmit')) {
  669. $threadtype = C::t('forum_threadtype')->fetch($_GET['sortid']);
  670. $showoption = '';
  671. $typevararr = C::t('forum_typevar')->fetch_all_by_sortid($_GET['sortid'], 'ASC');
  672. $typeoptionarr = C::t('forum_typeoption')->fetch_all(array_keys($typevararr));
  673. foreach($typevararr as $option) {
  674. $option['title'] = $typeoptionarr[$option['optionid']]['title'];
  675. $option['type'] = $typeoptionarr[$option['optionid']]['type'];
  676. $option['identifier'] = $typeoptionarr[$option['optionid']]['identifier'];
  677. $showoption .= '<button onclick="settip(this, \''.$option['identifier'].'\')" type="button">'.$option['title'].'</button>&nbsp;&nbsp;';
  678. }
  679. unset($typevararr, $typeoptionarr);
  680. showsubmenu('threadtype_infotypes', array(
  681. array('threadtype_infotypes_type', 'threadtypes', 1),
  682. array('threadtype_infotypes_content', 'threadtypes&operation=content', 0),
  683. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu), '', 0)
  684. ));
  685. showformheader("threadtypes&operation=sorttemplate&sortid={$_GET['sortid']}");
  686. echo '<script type="text/JavaScript">var currentAnchor = \'ltype\';</script>'.
  687. '<div class="itemtitle" style="width:100%;margin-bottom:5px;"><ul class="tab1" id="submenu">'.
  688. '<li id="nav_ttype" onclick="showanchor(this)" class="current"><a href="#"><span>'.$lang['threadtype_template_viewthread'].'</span></a></li>'.
  689. '<li id="nav_stype" onclick="showanchor(this)"><a href="#"><span>'.$lang['threadtype_template_forumdisplay'].'</span></a></li>'.
  690. '<li id="nav_ptype" onclick="showanchor(this)"><a href="#"><span>'.$lang['threadtype_template_post'].'</span></a></li>'.
  691. '<li id="nav_btype" onclick="showanchor(this)"><a href="#"><span>'.$lang['threadtype_template_diy'].'</span></a></li>'.
  692. '</ul></div>';
  693. echo '<div id="ttype">'.
  694. $showoption.
  695. '<div id="ttype_tip"></div>'.
  696. '<br /><textarea cols="100" rows="15" id="ttypetemplate" name="typetemplate" style="width: 95%;" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">'.dhtmlspecialchars($threadtype['template']).'</textarea>'.
  697. '</div>';
  698. echo '<div id="stype" style="display:none">'.
  699. '<button onclick="settip(this, \'subject\', \'subject/'.$lang['threadtype_template_threadtitle'].'|subject_url/'.$lang['threadtype_template_threadurl'].'|tid/'.$lang['threadtype_template_threadid'].'\')" type="button">'.$lang['threadtype_template_threadtitle'].'</button>&nbsp;&nbsp;'.
  700. '<textarea id="subject_sample" style="display:none" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)"><a href="{subject_url}">{subject}</a></textarea>'.
  701. '<button onclick="settip(this, \'\', \'dateline/'.$lang['threadtype_template_dateline'].'\')" type="button">'.$lang['threadtype_template_dateline'].'</button>&nbsp;&nbsp;'.
  702. '<button onclick="settip(this, \'author\', \'author/'.$lang['threadtype_template_author'].'|authorid/'.$lang['threadtype_template_authorid'].'|author_url/'.$lang['threadtype_template_authorurl'].'|avatar_small/'.$lang['threadtype_template_authoravatar'].'|author_verify/'.$lang['threadtype_template_authorverify'].'\')" type="button">'.$lang['threadtype_template_threadauthor'].'</button>&nbsp;&nbsp;'.
  703. '<textarea id="author_sample" style="display:none" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)"><a href="{author_url}">{author}</a></textarea>'.
  704. '<button onclick="settip(this, \'\', \'views/'.$lang['threadtype_template_threadviews'].'\')" type="button">'.$lang['threadtype_template_threadviews'].'</button>&nbsp;&nbsp;'.
  705. '<button onclick="settip(this, \'\', \'replies/'.$lang['threadtype_template_threadreplies'].'\')" type="button">'.$lang['threadtype_template_threadreplies'].'</button>&nbsp;&nbsp;'.
  706. '<button onclick="settip(this, \'lastpost\', \'lastpost/'.$lang['threadtype_template_lastpostdateline'].'|lastpost_url/'.$lang['threadtype_template_lastposturl'].'|lastposter/'.$lang['threadtype_template_lastpostuser'].'|lastposter_url/'.$lang['threadtype_template_lastpostuserurl'].'\')" type="button">'.$lang['threadtype_template_lastpost'].'</button>&nbsp;&nbsp;'.
  707. '<textarea id="lastpost_sample" style="display:none" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)"><a href="{lastpost_url}">{lastpost}</a> by <a href="{lastposter_url}">{lastposter}</a></textarea>'.
  708. '<button onclick="settip(this, \'typename\', \'typename/'.$lang['threadtype_template_threadtypename'].'|typename_url/'.$lang['threadtype_template_threadtypeurl'].'\')" type="button">'.$lang['threadtype_template_threadtype'].'</button>&nbsp;&nbsp;'.
  709. '<textarea id="typename_sample" style="display:none" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)"><a href="{typename_url}">{typename}</a></textarea>'.
  710. '<button onclick="settip(this, \'\', \'attachment/'.$lang['threadtype_template_attachmentexist'].'\')" type="button">'.$lang['threadtype_template_attachment'].'</button>&nbsp;&nbsp'.
  711. '<button onclick="settip(this, \'\', \'modcheck/'.$lang['threadtype_template_modcheck'].'\')" type="button">'.$lang['threadtype_template_threadmod'].'</button>&nbsp;&nbsp'.
  712. '<button onclick="settip(this, \'loop\', \'/'.$lang['threadtype_template_loop'].'\')" type="button">[loop]...[/loop]</button>&nbsp;&nbsp;'.
  713. '<textarea id="loop_sample" style="display:none" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">
  714. <table><tr><td>'.$lang['threadtype_template_title'].'</td></tr>
  715. [loop]<tr><td><a href="{subject_url}">{subject}</a></td></tr>[/loop]
  716. </table>
  717. </textarea>'.
  718. '<br />'.
  719. $showoption.
  720. '<div id="stype_tip"></div>'.
  721. '<br /><textarea cols="100" rows="15" id="stypetemplate" name="stypetemplate" style="width: 95%;" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">'.dhtmlspecialchars($threadtype['stemplate']).'</textarea>'.
  722. '</div>';
  723. echo '<div id="ptype" style="display:none">'.
  724. $showoption.
  725. '<div id="ptype_tip"></div>'.
  726. '<br /><textarea cols="100" rows="15" id="ptypetemplate" name="ptypetemplate" style="width: 95%;" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">'.dhtmlspecialchars($threadtype['ptemplate']).'</textarea>'.
  727. '</div>';
  728. echo '<div id="btype" style="display:none">'.
  729. '<button onclick="settip(this, \'subject\', \'subject/'.$lang['threadtype_template_threadtitle'].'|subject_url/'.$lang['threadtype_template_threadurl'].'|tid/'.$lang['threadtype_template_threadid'].'\')" type="button">'.$lang['threadtype_template_threadtitle'].'</button>&nbsp;&nbsp;'.
  730. '<button onclick="settip(this, \'\', \'dateline/'.$lang['threadtype_template_dateline'].'\')" type="button">'.$lang['threadtype_template_dateline'].'</button>&nbsp;&nbsp;'.
  731. '<button onclick="settip(this, \'author\', \'author/'.$lang['threadtype_template_author'].'|authorid/'.$lang['threadtype_template_authorid'].'|author_url/'.$lang['threadtype_template_authorurl'].'|avatar_small/'.$lang['threadtype_template_authoravatar'].'|author_verify/'.$lang['threadtype_template_authorverify'].'\')" type="button">'.$lang['threadtype_template_threadauthor'].'</button>&nbsp;&nbsp;'.
  732. '<button onclick="settip(this, \'\', \'views/'.$lang['threadtype_template_threadviews'].'\')" type="button">'.$lang['threadtype_template_threadviews'].'</button>&nbsp;&nbsp;'.
  733. '<button onclick="settip(this, \'\', \'replies/'.$lang['threadtype_template_threadreplies'].'\')" type="button">'.$lang['threadtype_template_threadreplies'].'</button>&nbsp;&nbsp;'.
  734. '<button onclick="settip(this, \'lastpost\', \'lastpost/'.$lang['threadtype_template_lastpostdateline'].'|lastpost_url/'.$lang['threadtype_template_lastposturl'].'|lastposter/'.$lang['threadtype_template_lastpostuser'].'|lastposter_url/'.$lang['threadtype_template_lastpostuserurl'].'\')" type="button">'.$lang['threadtype_template_lastpost'].'</button>&nbsp;&nbsp;'.
  735. '<button onclick="settip(this, \'typename\', \'typename/'.$lang['threadtype_template_threadtypename'].'|typename_url/'.$lang['threadtype_template_threadtypeurl'].'\')" type="button">'.$lang['threadtype_template_threadtype'].'</button>&nbsp;&nbsp;'.
  736. '<button onclick="settip(this, \'\', \'attachment/'.$lang['threadtype_template_attachmentexist'].'\')" type="button">'.$lang['threadtype_template_attachment'].'</button>&nbsp;&nbsp'.
  737. '<button onclick="settip(this, \'loop\', \'/'.$lang['threadtype_template_loop'].'\')" type="button">[loop]...[/loop]</button>&nbsp;&nbsp;'.
  738. '<br />'.
  739. $showoption.
  740. '<div id="btype_tip"></div>'.
  741. '<br /><textarea cols="100" rows="15" id="btypetemplate" name="btypetemplate" style="width: 95%;" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">'.dhtmlspecialchars($threadtype['btemplate']).'</textarea>'.
  742. '</div>'.
  743. '<input type="submit" class="btn" name="sorttemplatesubmit" value="'.$lang['submit'].'"></form>';
  744. echo '<script>
  745. function settip(obj, id, tips) {
  746. var tips = !tips ? 0 : tips.split(\'|\');
  747. var tipid = obj.parentNode.id + \'_tip\', s1 = \'\', s2 = \'\', s3 = \'\';
  748. if(!tips) {
  749. s1 += \'<td>{\' + id + \'}</td>\';
  750. s2 += \'<td>'.$lang['threadtype_template_varname'].'(\' + obj.innerHTML + \')</td>\';
  751. s1 += \'<td>{\' + id + \'_value}</td>\';
  752. s2 += \'<td>'.$lang['threadtype_template_varvalue'].'</td>\';
  753. s1 += \'<td>{\' + id + \'_unit}</td>\';
  754. s2 += \'<td>'.$lang['threadtype_template_varunit'].'</td>\';
  755. if(obj.parentNode.id == \'ptype\') {
  756. s1 += \'<td>{\' + id + \'_required}</td>\';
  757. s2 += \'<td>'.$lang['threadtype_template_requiredflag'].'</td>\';
  758. s1 += \'<td>{\' + id + \'_tips}</td>\';
  759. s2 += \'<td>'.$lang['threadtype_template_tipflag'].'</td>\';
  760. s1 += \'<td>{\' + id + \'_description}</td>\';
  761. s2 += \'<td>'.$lang['threadtype_template_briefdes'].'</td>\';
  762. }
  763. if(obj.parentNode.id == \'ptype\') {
  764. s3 = \'<dt><strong class="rq">{\' + id + \'_required}</strong>{\' + id + \'}</dt><dd>{\' + id + \'_value} {\' + id + \'_unit} {\' + id + \'_tips} {\' + id + \'_description}</dd>\r\n\';
  765. } else {
  766. s3 = obj.parentNode.id == \'ttype\' ? \'<dt>{\' + id + \'}:</dt><dd>{\' + id + \'_value} {\' + id + \'_unit}</dd>\r\n\' : \'<p><em>{\' + id + \'}:</em>{\' + id + \'_value} {\' + id + \'_unit}</p>\r\n\';
  767. }
  768. } else {
  769. for(i = 0;i < tips.length;i++) {
  770. var i0 = tips[i].substr(0, tips[i].indexOf(\'/\'));
  771. var i1 = tips[i].substr(tips[i].indexOf(\'/\') + 1);
  772. if(i0) {
  773. s1 += \'<td>{\' + i0 + \'}</td>\';
  774. }
  775. s2 += \'<td>\' + i1 + \'</td>\';
  776. }
  777. if($(id + \'_sample\')) {
  778. s3 = $(id + \'_sample\').innerHTML;
  779. }
  780. }
  781. $(tipid).innerHTML = \'<table class="tb tb2">\' +
  782. (s1 ? \'<tr><td class="bold" width="50">'.$lang['threadtype_template_tag'].'</td>\' + s1 + \'</tr>\' : \'\') +
  783. \'<tr><td class="bold" width="50">'.$lang['threadtype_template_intro'].'</td>\' + s2 + \'</tr></table>\';
  784. if(s3) {
  785. $(tipid).innerHTML += \'<table class="tb tb2"><tr><td class="bold" width="50">'.$lang['threadtype_template_example'].'</td><td colspan="6"><textarea style="width: 95%;" rows="2" readonly onclick="this.select()" id="\' + obj.parentNode.id + \'_sample">\' + s3 + \'</textarea></td></tr></table>\';
  786. }
  787. }
  788. </script>';
  789. } else {
  790. C::t('forum_threadtype')->update($_GET['sortid'], array(
  791. 'special' => 1,
  792. 'template' => $_GET['typetemplate'],
  793. 'stemplate' => $_GET['stypetemplate'],
  794. 'ptemplate' => $_GET['ptypetemplate'],
  795. 'btemplate' => $_GET['btypetemplate'],
  796. 'expiration' => $_GET['typeexpiration'],
  797. ));
  798. updatecache('threadsorts');
  799. cpmsg('threadtype_infotypes_succeed', 'action=threadtypes&operation=sorttemplate&sortid='.$_GET['sortid'], 'succeed');
  800. }
  801. } elseif($operation == 'content') {
  802. if(!submitcheck('searchsortsubmit', 1) && !submitcheck('delsortsubmit') && !submitcheck('sendpmsubmit')) {
  803. shownav('forum', 'threadtype_infotypes');
  804. showsubmenu('threadtype_infotypes', array(
  805. array('threadtype_infotypes_type', 'threadtypes', 0),
  806. array('threadtype_infotypes_content', 'threadtypes&operation=content', 1),
  807. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu))
  808. ));
  809. $_GET['sortid'] = intval($_GET['sortid']);
  810. $threadtypes = '<select name="sortid" onchange="window.location.href = \'?action=threadtypes&operation=content&sortid=\'+ this.options[this.selectedIndex].value"><option value="0">'.cplang('none').'</option>';
  811. $query = C::t('forum_threadtype')->fetch_all_for_order();
  812. foreach($query as $type) {
  813. $threadtypes .= '<option value="'.$type['typeid'].'" '.($_GET['sortid'] == $type['typeid'] ? 'selected="selected"' : '').'>'.dhtmlspecialchars($type['name']).'</option>';
  814. }
  815. $threadtypes .= '</select>';
  816. showformheader('threadtypes&operation=content');
  817. showtableheader('threadtype_content_choose');
  818. showsetting('threadtype_content_name', '', '', $threadtypes);
  819. if($_GET['sortid']) {
  820. showtableheader('threadtype_content_sort_by_conditions');
  821. loadcache(array('threadsort_option_'.$_GET['sortid']));
  822. $sortoptionarray = $_G['cache']['threadsort_option_'.$_GET['sortid']];
  823. if(is_array($sortoptionarray)) foreach($sortoptionarray as $optionid => $option) {
  824. $optionshow = '';
  825. if($option['search']) {
  826. if(in_array($option['type'], array('radio', 'checkbox', 'select'))){
  827. if($option['type'] == 'select') {
  828. $optionshow .= '<select name="searchoption['.$optionid.'][value]"><option value="0">'.cplang('unlimited').'</option>';
  829. foreach($option['choices'] as $id => $value) {
  830. $optionshow .= '<option value="'.$id.'" '.($_GET['searchoption'][$optionid]['value'] == $id ? 'selected="selected"' : '').'>'.$value.'</option>';
  831. }
  832. $optionshow .= '</select><input type="hidden" name="searchoption['.$optionid.'][type]" value="select">';
  833. } elseif($option['type'] == 'radio') {
  834. $optionshow .= '<input type="radio" class="radio" name="searchoption['.$optionid.'][value]" value="0" checked="checked"]>'.cplang('unlimited').'&nbsp;';
  835. foreach($option['choices'] as $id => $value) {
  836. $optionshow .= '<input type="radio" class="radio" name="searchoption['.$optionid.'][value]" value="'.$id.'" '.($_GET['searchoption'][$optionid]['value'] == $id ? 'checked="checked"' : '').'> '.$value.' &nbsp;';
  837. }
  838. $optionshow .= '<input type="hidden" name="searchoption['.$optionid.'][type]" value="radio">';
  839. } elseif($option['type'] == 'checkbox') {
  840. foreach($option['choices'] as $id => $value) {
  841. $optionshow .= '<input type="checkbox" class="checkbox" name="searchoption['.$optionid.'][value]['.$id.']" value="'.$id.'" '.($_GET['searchoption'][$optionid]['value'] == $id ? 'checked="checked"' : '').'> '.$value.'';
  842. }
  843. $optionshow .= '<input type="hidden" name="searchoption['.$optionid.'][type]" value="checkbox">';
  844. }
  845. } elseif(in_array($option['type'], array('number', 'text', 'email', 'calendar', 'image', 'url', 'textarea', 'upload', 'range'))) {
  846. if ($option['type'] == 'calendar') {
  847. $optionshow .= '<script type="text/javascript" src="'.$_G['setting']['jspath'].'calendar.js?'.VERHASH.'"></script><input type="text" name="searchoption['.$optionid.'][value]" class="txt" value="'.$_GET['searchoption'][$optionid]['value'].'" onclick="showcalendar(event, this, false)" />';
  848. } elseif($option['type'] == 'number') {
  849. $optionshow .= '<select name="searchoption['.$optionid.'][condition]">
  850. <option value="0" '.($_GET['searchoption'][$optionid]['condition'] == 0 ? 'selected="selected"' : '').'>'.cplang('equal_to').'</option>
  851. <option value="1" '.($_GET['searchoption'][$optionid]['condition'] == 1 ? 'selected="selected"' : '').'>'.cplang('more_than').'</option>
  852. <option value="2" '.($_GET['searchoption'][$optionid]['condition'] == 2 ? 'selected="selected"' : '').'>'.cplang('lower_than').'</option>
  853. </select>&nbsp;&nbsp;
  854. <input type="text" class="txt" name="searchoption['.$optionid.'][value]" value="'.$_GET['searchoption'][$optionid]['value'].'" />
  855. <input type="hidden" name="searchoption['.$optionid.'][type]" value="number">';
  856. } elseif($option['type'] == 'range') {
  857. $optionshow .= '<input type="text" name="searchoption['.$optionid.'][value][min]" size="16" value="'.$_GET['searchoption'][$optionid]['value']['min'].'" /> -
  858. <input type="text" name="searchoption['.$optionid.'][value][max]" size="16" value="'.$_GET['searchoption'][$optionid]['value']['max'].'" />
  859. <input type="hidden" name="searchoption['.$optionid.'][type]" value="range">';
  860. } else {
  861. $optionshow .= '<input type="text" name="searchoption['.$optionid.'][value]" class="txt" value="'.$_GET['searchoption'][$optionid]['value'].'" />';
  862. }
  863. }
  864. $optionshow .= '&nbsp;'.$option['unit'];
  865. showsetting($option['title'], '', '', $optionshow);
  866. }
  867. }
  868. }
  869. showsubmit('searchsortsubmit', 'submit');
  870. showtablefooter();
  871. showformfooter();
  872. } else {
  873. if(submitcheck('searchsortsubmit', 1)) {
  874. if(empty($_GET['searchoption']) && !$_GET['sortid']) {
  875. cpmsg('threadtype_content_no_choice', 'action=threadtypes&operation=content', 'error');
  876. }
  877. $mpurl = ADMINSCRIPT.'?action=threadtypes&operation=content&sortid='.$_GET['sortid'].'&searchsortsubmit=true';
  878. if(!is_array($_GET['searchoption'])) {
  879. $mpurl .= '&searchoption='.$_GET['searchoption'];
  880. $_GET['searchoption'] = dunserialize(base64_decode($_GET['searchoption']));
  881. } else {
  882. $mpurl .= '&searchoption='.base64_encode(serialize($_GET['searchoption']));
  883. }
  884. shownav('forum', 'threadtype_infotypes');
  885. showsubmenu('threadtype_infotypes', array(
  886. array('threadtype_infotypes_type', 'threadtypes', 0),
  887. array('threadtype_infotypes_content', 'threadtypes&operation=content', 1),
  888. array(array('menu' => ($curclassname ? $curclassname : 'threadtype_infotypes_option'), 'submenu' => $classoptionmenu))
  889. ));
  890. loadcache('forums');
  891. loadcache(array('threadsort_option_'.$_GET['sortid']));
  892. require_once libfile('function/threadsort');
  893. sortthreadsortselectoption($_GET['sortid']);
  894. $sortoptionarray = $_G['cache']['threadsort_option_'.$_GET['sortid']];
  895. $selectsql = '';
  896. if($_GET['searchoption']) {
  897. foreach($_GET['searchoption'] as $optionid => $option) {
  898. $fieldname = $sortoptionarray[$optionid]['identifier'] ? $sortoptionarray[$optionid]['identifier'] : 1;
  899. if($option['value']) {
  900. if(in_array($option['type'], array('number', 'radio'))) {
  901. $option['value'] = intval($option['value']);
  902. $exp = '=';
  903. if($option['condition']) {
  904. $exp = $option['condition'] == 1 ? '>' : '<';
  905. }
  906. $sql = "$fieldname$exp'$option[value]'";
  907. } elseif($option['type'] == 'select') {
  908. $subvalues = $currentchoices = array();
  909. if(!empty($sortoptionarray)) {
  910. foreach($sortoptionarray as $subkey => $subvalue) {
  911. if($subvalue['identifier'] == $fieldname) {
  912. $currentchoices = $subvalue['choices'];
  913. break;
  914. }
  915. }
  916. }
  917. if(!empty($currentchoices)) {
  918. foreach($currentchoices as $subkey => $subvalue) {
  919. if(preg_match('/^'.$option['value'].'/i', $subkey)) {
  920. $subvalues[] = $subkey;
  921. }
  922. }
  923. }
  924. $sql = "$fieldname IN (".dimplode($subvalues).")";
  925. } elseif($option['type'] == 'checkbox') {
  926. $sql = "$fieldname LIKE '%".(implode("%", $option['value']))."%'";
  927. } elseif($option['type'] == 'range') {
  928. $sql = $option['value']['min'] || $option['value']['max'] ? "$fieldname BETWEEN ".intval($option['value']['min'])." AND ".intval($option['value']['max'])."" : '';
  929. } else {
  930. $sql = "$fieldname LIKE '%$option[value]%'";
  931. }
  932. $selectsql .= $and."$sql ";
  933. $and = 'AND ';
  934. }
  935. }
  936. $selectsql = trim($selectsql);
  937. $searchtids = C::t('forum_optionvalue')->fetch_all_tid($_GET['sortid'], $selectsql ? 'WHERE '.$selectsql : '');
  938. }
  939. if($searchtids) {
  940. $lpp = max(5, empty($_GET['lpp']) ? 50 : intval($_GET['lpp']));
  941. $start_limit = ($page - 1) * $lpp;
  942. $threadcount = C::t('forum_thread')->count_by_tid_fid($searchtids);
  943. if($threadcount) {
  944. foreach(C::t('forum_thread')->fetch_all_by_tid($searchtids, $start_limit, $lpp) as $thread) {
  945. $threads .= showtablerow('', array('class="td25"', '', '', 'class="td28"', 'class="td28"'), array(
  946. "<input class=\"checkbox\" type=\"checkbox\" name=\"tidsarray[]\" value=\"$thread[tid]\"/>".
  947. "<input type=\"hidden\" name=\"fidsarray[]\" value=\"$thread[fid]\"/>",
  948. "<a href=\"forum.php?mod=viewthread&tid=$thread[tid]\" target=\"_blank\">$thread[subject]</a>",
  949. "<a href=\"forum.php?mod=forumdisplay&fid=$thread[fid]\" target=\"_blank\">{$_G['cache'][forums][$thread[fid]][name]}</a>",
  950. "<a href=\"home.php?mod=space&uid=$thread[authorid]\" target=\"_blank\">$thread[author]</a>",
  951. $thread['replies'],
  952. $thread['views'],
  953. dgmdate($thread['lastpost'], 'd'),
  954. ), TRUE);
  955. }
  956. $multipage = multi($threadcount, $lpp, $page, $mpurl, 0, 3);
  957. }
  958. }
  959. showformheader('threadtypes&operation=content');
  960. showtableheader('admin', 'fixpadding');
  961. showsubtitle(array('', 'subject', 'forum', 'author', 'threads_replies', 'threads_views', 'threads_lastpost'));
  962. echo $threads;
  963. echo $multipage;
  964. showsubmit('', '', '', "<input type=\"submit\" class=\"btn\" name=\"delsortsubmit\" value=\"{$lang[threadtype_content_delete]}\"/>");
  965. showtablefooter();
  966. showformfooter();
  967. } elseif(submitcheck('delsortsubmit')) {
  968. require_once libfile('function/post');
  969. if($_GET['tidsarray']) {
  970. require_once libfile('function/delete');
  971. deletethread($_GET['tidsarray']);
  972. if($_G['setting']['globalstick']) {
  973. updatecache('globalstick');
  974. }
  975. if($_GET['fidsarray']) {
  976. foreach(explode(',', $_GET['fidsarray']) as $fid) {
  977. updateforumcount(intval($fid));
  978. }
  979. }
  980. }
  981. cpmsg('threadtype_content_delete_succeed', 'action=threadtypes&operation=content', 'succeed');
  982. }
  983. }
  984. } elseif($operation == 'classlist') {
  985. $classoptions = '';
  986. $classidarray = array();
  987. $classid = $_GET['classid'] ? $_GET['classid'] : 0;
  988. foreach(C::t('forum_typeoption')->fetch_all_by_classid($classid) as $option) {
  989. $classidarray[] = $option['optionid'];
  990. $classoptions .= "<a href=\"#ol\" onclick=\"ajaxget('".ADMINSCRIPT."?action=threadtypes&operation=optionlist&typeid={$_GET['typeid']}&classid=$option[optionid]', 'optionlist', 'optionlist', 'Loading...', '', checkedbox)\">$option[title]</a> &nbsp; ";
  991. }
  992. include template('common/header');
  993. echo $classoptions;
  994. include template('common/footer');
  995. exit;
  996. } elseif($operation == 'optionlist') {
  997. $classid = $_GET['classid'];
  998. if(!$classid) {
  999. $classid = C::t('forum_typeoption')->fetch_all_by_classid(0, 0, 1);
  1000. $classid = $classid[0]['optionid'];
  1001. }
  1002. $option = $options = array();
  1003. foreach(C::t('forum_typevar')->fetch_all_by_sortid($_GET['typeid']) as $option) {
  1004. $options[] = $option['optionid'];
  1005. }
  1006. $optionlist = '';
  1007. foreach(C::t('forum_typeoption')->fetch_all_by_classid($classid) as $option) {
  1008. $optionlist .= "<input ".(in_array($option['optionid'], $options) ? ' checked="checked" ' : '')."class=\"checkbox\" type=\"checkbox\" name=\"typeselect[]\" id=\"typeselect_$option[optionid]\" value=\"$option[optionid]\" onclick=\"insertoption(this.value);\" /><label for=\"typeselect_$option[optionid]\">".dhtmlspecialchars($option['title'])."</label>&nbsp;&nbsp;";
  1009. }
  1010. include template('common/header');
  1011. echo $optionlist;
  1012. include template('common/footer');
  1013. exit;
  1014. } elseif($operation == 'sortlist') {
  1015. $optionid = $_GET['optionid'];
  1016. $option = C::t('forum_typeoption')->fetch($optionid);
  1017. include template('common/header');
  1018. $option['type'] = $lang['threadtype_edit_vars_type_'. $option['type']];
  1019. $option['available'] = 1;
  1020. showtablerow('', array('class="td25"', 'class="td28 td23"'), array(
  1021. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$option[optionid]\" ".($option['model'] ? 'disabled' : '').">",
  1022. "<input type=\"text\" class=\"txt\" size=\"2\" name=\"displayorder[$option[optionid]]\" value=\"$option[displayorder]\">",
  1023. "<input class=\"checkbox\" type=\"checkbox\" name=\"available[$option[optionid]]\" value=\"1\" ".($option['available'] ? 'checked' : '')." ".($option['model'] ? 'disabled' : '').">",
  1024. dhtmlspecialchars($option['title']),
  1025. $option[type],
  1026. "<input class=\"checkbox\" type=\"checkbox\" name=\"required[$option[optionid]]\" value=\"1\" ".($option['required'] ? 'checked' : '')." ".($option['model'] ? 'disabled' : '').">",
  1027. "<input class=\"checkbox\" type=\"checkbox\" name=\"unchangeable[$option[optionid]]\" value=\"1\" ".($option['unchangeable'] ? 'checked' : '').">",
  1028. "<input class=\"checkbox\" type=\"checkbox\" name=\"search[$option[optionid]][form]\" value=\"1\" ".(getstatus($option['search'], 1) == 1 ? 'checked' : '').">",
  1029. "<input class=\"checkbox\" type=\"checkbox\" name=\"search[$option[optionid]][font]\" value=\"1\" ".(getstatus($option['search'], 2) == 1 ? 'checked' : '').">",
  1030. "<input class=\"checkbox\" type=\"checkbox\" name=\"subjectshow[$option[optionid]]\" value=\"1\" ".($option['subjectshow'] ? 'checked' : '').">",
  1031. "<a href=\"".ADMINSCRIPT."?action=threadtypes&operation=optiondetail&optionid=$option[optionid]\" class=\"act\">".$lang['edit']."</a>"
  1032. ));
  1033. include template('common/footer');
  1034. exit;
  1035. } elseif($operation == 'import') {
  1036. $sortid = 0;
  1037. $newthreadtype = getimportdata('Discuz! Threadtypes');
  1038. if($newthreadtype) {
  1039. $idcmp = $searcharr = $replacearr = $indexoption = array();
  1040. $create_tableoption_sql = $separator = '';
  1041. $i = 0;
  1042. foreach($newthreadtype as $key => $value) {
  1043. if(!$i) {
  1044. if($newname1 = trim(strip_tags($value['name']))) {
  1045. $findname = 0;
  1046. $tmpnewname1 = $newname1;
  1047. $decline = '_';
  1048. while(!$findname) {
  1049. if(C::t('forum_threadtype')->checkname($tmpnewname1)) {
  1050. $tmpnewname1 = $newname1.$decline;
  1051. $decline .= '_';
  1052. } else {
  1053. $findname = 1;
  1054. }
  1055. }
  1056. $newname1 = $tmpnewname1;
  1057. $data = array(
  1058. 'name' => $newname1,
  1059. 'description' => dhtmlspecialchars(trim($value['ttdescription'])),
  1060. 'special' => 1,
  1061. );
  1062. $sortid = C::t('forum_threadtype')->insert($data, 1);
  1063. }
  1064. $i = 1;
  1065. if(empty($value['identifier'])) {
  1066. cpmsg('threadtype_import_succeed', 'action=threadtypes', 'succeed');
  1067. }
  1068. }
  1069. $typeoption = array(
  1070. 'classid' => $value['classid'],
  1071. 'expiration' => $value['tpexpiration'],
  1072. 'protect' => $value['protect'],
  1073. 'title' => $value['title'],
  1074. 'description' => $value['tpdescription'],
  1075. 'type' => $value['type'],
  1076. 'unit' => $value['unit'],
  1077. 'rules' => $value['rules'],
  1078. 'permprompt' => $value['permprompt'],
  1079. );
  1080. if(strlen($value['identifier']) > 34) {
  1081. cpmsg('threadtype_infotypes_optionvariable_invalid', 'action=threadtypes', 'error');
  1082. }
  1083. $findidentifier = 0;
  1084. $tmpidentifier = $value['identifier'];
  1085. $decline = '_';
  1086. while(!$findidentifier) {
  1087. if(C::t('forum_typeoption')->fetch_all_by_identifier($tmpidentifier, 0, 1) || !ispluginkey($tmpidentifier) || in_array(strtoupper($tmpidentifier), $mysql_keywords)) {
  1088. $tmpidentifier = $value['identifier'].$decline.$sortid;
  1089. $decline .= '_';
  1090. } else {
  1091. $findidentifier = 1;
  1092. }
  1093. }
  1094. $typeoption['identifier'] = $tmpidentifier;
  1095. $idcmp[$value['identifier']] = $tmpidentifier;
  1096. $newoptionid = C::t('forum_typeoption')->insert($typeoption, true);
  1097. $typevar = array(
  1098. 'sortid' => $sortid,
  1099. 'optionid' => $newoptionid,
  1100. 'available' => $value['available'],
  1101. 'required' => $value['required'],
  1102. 'unchangeable' => $value['unchangeable'],
  1103. 'search' => $value['search'],
  1104. 'displayorder' => $value['displayorder'],
  1105. 'subjectshow' => $value['subjectshow'],
  1106. );
  1107. C::t('forum_typevar')->insert($typevar);
  1108. if($tmpidentifier) {
  1109. if(in_array($value['type'], array('radio'))) {
  1110. $create_tableoption_sql .= "$separator$tmpidentifier smallint(6) UNSIGNED NOT NULL DEFAULT '0'";
  1111. } elseif(in_array($value['type'], array('number', 'range'))) {
  1112. $create_tableoption_sql .= "$separator$tmpidentifier int(10) UNSIGNED NOT NULL DEFAULT '0'";
  1113. } elseif($value['type'] == 'select') {
  1114. $create_tableoption_sql .= "$separator$tmpidentifier varchar(50) NOT NULL";
  1115. } else {
  1116. $create_tableoption_sql .= "$separator$tmpidentifier mediumtext NOT NULL";
  1117. }
  1118. $separator = ' ,';
  1119. if(in_array($value['type'], array('radio', 'select', 'number'))) {
  1120. $indexoption[] = $tmpidentifier;
  1121. }
  1122. }
  1123. }
  1124. foreach($idcmp as $k => $v) {
  1125. if($k != $v) {
  1126. $searcharr[] = '{'.$k;
  1127. $searcharr[] = '['.$k;
  1128. $replacearr[] = '{'.$v;
  1129. $replacearr[] = '['.$v;
  1130. }
  1131. }
  1132. $threadtype = array(
  1133. 'icon' => $value['icon'],
  1134. 'special' => $value['special'],
  1135. 'modelid' => $value['modelid'],
  1136. 'expiration' => $value['ttexpiration'],
  1137. 'template' => str_replace($searcharr, $replacearr, $value['template']),
  1138. 'stemplate' => str_replace($searcharr, $replacearr, $value['stemplate']),
  1139. 'ptemplate' => str_replace($searcharr, $replacearr, $value['ptemplate']),
  1140. 'btemplate' => str_replace($searcharr, $replacearr, $value['btemplate']),
  1141. );
  1142. DB::update('forum_threadtype', $threadtype, array('typeid' => $sortid));
  1143. $fields = ($create_tableoption_sql ? $create_tableoption_sql.',' : '')."tid mediumint(8) UNSIGNED NOT NULL DEFAULT '0',fid smallint(6) UNSIGNED NOT NULL DEFAULT '0',dateline int(10) UNSIGNED NOT NULL DEFAULT '0',expiration int(10) UNSIGNED NOT NULL DEFAULT '0',";
  1144. $fields .= "KEY (fid), KEY(dateline)";
  1145. if($indexoption) {
  1146. foreach($indexoption as $index) {
  1147. $fields .= "$separator KEY $index ($index)";
  1148. $separator = ' ,';
  1149. }
  1150. }
  1151. $dbcharset = $_G['config']['db'][1]['dbcharset'];
  1152. $dbcharset = empty($dbcharset) ? str_replace('-','',CHARSET) : $dbcharset;
  1153. C::t('forum_optionvalue')->create($sortid, $fields, $dbcharset);
  1154. updatecache('threadsorts');
  1155. }
  1156. cpmsg('threadtype_import_succeed', 'action=threadtypes', 'succeed');
  1157. } elseif($operation == 'export') {
  1158. $sortid = intval($_GET['sortid']);
  1159. $typevarlist = array();
  1160. $typevararr = C::t('forum_typevar')->fetch_all_by_sortid($sortid);
  1161. $typeoptionarr = C::t('forum_typeoption')->fetch_all(array_keys($typevararr));
  1162. $threadtypearr = C::t('forum_threadtype')->fetch($sortid);
  1163. foreach($typevararr as $typevar) {
  1164. $typeoption = $typeoptionarr[$typevar['optionid']];
  1165. $typevar = array_merge($threadtypearr, $typevar);
  1166. $typevar = array_merge($typeoption, $typevar);
  1167. $typevar['tpdescription'] = $typeoption['description'];
  1168. $typevar['ttdescription'] = $threadtypearr['description'];
  1169. $typevar['tpexpiration'] = $typeoption['expiration'];
  1170. $typevar['ttexpiration'] = $threadtypearr['expiration'];
  1171. unset($typevar['fid']);
  1172. $typevarlist[] = $typevar;
  1173. }
  1174. if(empty($typevarlist)) {
  1175. $threadtype = C::t('forum_threadtype')->fetch($sortid);
  1176. $threadtype['ttdescription'] = $threadtype['description'];
  1177. unset($threadtype['fid']);
  1178. $typevarlist[] = $threadtype;
  1179. }
  1180. if(empty($typevarlist)) {
  1181. cpmsg('threadtype_export_error');
  1182. }
  1183. exportdata('Discuz! Threadtypes', $typevarlist[0]['typeid'], $typevarlist);
  1184. }
  1185. ?>