tpl.func.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function _tpl_form_field_date($name, $value = '', $withtime = false) {
  8. $s = '';
  9. $withtime = empty($withtime) ? false : true;
  10. if (!empty($value)) {
  11. $value = strexists($value, '-') ? strtotime($value) : $value;
  12. } else {
  13. $value = TIMESTAMP;
  14. }
  15. $value = ($withtime ? date('Y-m-d H:i:s', $value) : date('Y-m-d', $value));
  16. $s .= '<input type="text" name="' . $name . '" value="'.$value.'" placeholder="请选择日期时间" readonly="readonly" class="datetimepicker form-control" style="padding-left:12px;" />';
  17. $s .= '
  18. <script type="text/javascript">
  19. require(["datetimepicker"], function(){
  20. var option = {
  21. lang : "zh",
  22. step : 5,
  23. timepicker : ' . (!empty($withtime) ? "true" : "false") .',
  24. closeOnDateSelect : true,
  25. format : "Y-m-d' . (!empty($withtime) ? ' H:i"' : '"') .'
  26. };
  27. $(".datetimepicker[name = \'' . $name . '\']").datetimepicker(option);
  28. });
  29. </script>';
  30. return $s;
  31. }
  32. function tpl_form_field_link($name, $value = '', $options = array()) {
  33. global $_GPC, $_W;
  34. if(!empty($options)) {
  35. foreach ($options as $key => $val){
  36. $options .= $key.':'.$val.',';
  37. }
  38. }
  39. $s = '';
  40. if (!defined('TPL_INIT_LINK')) {
  41. $s .= '
  42. <script type="text/javascript">
  43. window.HOST_TYPE = "2";
  44. window.BMap_loadScriptTime = (new Date).getTime();
  45. function showLinkDialog(elm) {
  46. var ipt = $(elm).parent().parent().parent().prev();
  47. util.linkBrowser(function(href){
  48. var multiid = "'. $_GPC['multiid'] .'";
  49. if (multiid) {
  50. href = /(&)?t=/.test(href) ? href : href + "&t=" + multiid;
  51. }
  52. ipt.val(href);
  53. });
  54. }
  55. function newsLinkDialog(elm, page) {
  56. var ipt = $(elm).parent().parent().parent().prev();
  57. util.newsBrowser(function(href, page){
  58. if (page != "" && page != undefined) {
  59. newsLinkDialog(elm, page);
  60. return false;
  61. }
  62. var multiid = "'. $_GPC['multiid'] .'";
  63. if (multiid) {
  64. href = /(&)?t=/.test(href) ? href : href + "&t=" + multiid;
  65. }
  66. ipt.val(href);
  67. }, page);
  68. }
  69. function pageLinkDialog(elm, page) {
  70. var ipt = $(elm).parent().parent().parent().prev();
  71. util.pageBrowser(function(href, page){
  72. if (page != "" && page != undefined) {
  73. pageLinkDialog(elm, page);
  74. return false;
  75. }
  76. var multiid = "'. $_GPC['multiid'] .'";
  77. if (multiid) {
  78. href = /(&)?t=/.test(href) ? href : href + "&t=" + multiid;
  79. }
  80. ipt.val(href);
  81. }, page);
  82. }
  83. function articleLinkDialog(elm, page) {
  84. var ipt = $(elm).parent().parent().parent().prev();
  85. util.articleBrowser(function(href, page){
  86. if (page != "" && page != undefined) {
  87. articleLinkDialog(elm, page);
  88. return false;
  89. }
  90. var multiid = "'. $_GPC['multiid'] .'";
  91. if (multiid) {
  92. href = /(&)?t=/.test(href) ? href : href + "&t=" + multiid;
  93. }
  94. ipt.val(href);
  95. }, page);
  96. }
  97. function phoneLinkDialog(elm, page) {
  98. var ipt = $(elm).parent().parent().parent().prev();
  99. util.phoneBrowser(function(href, page){
  100. if (page != "" && page != undefined) {
  101. phoneLinkDialog(elm, page);
  102. return false;
  103. }
  104. ipt.val(href);
  105. }, page);
  106. }
  107. function mapLinkDialog(elm) {
  108. var ipt = $(elm).parent().parent().parent().prev();
  109. util.map(elm, function(val){
  110. var href = \'https://api.map.baidu.com/marker?location=\'+val.lat+\',\'+val.lng+\'&output=html&src=we7\';
  111. var multiid = "'. $_GPC['multiid'] .'";
  112. if (multiid) {
  113. href = /(&)?t=/.test(href) ? href : href + "&t=" + multiid;
  114. }
  115. ipt.val(href);
  116. });
  117. }
  118. </script>';
  119. define('TPL_INIT_LINK', true);
  120. }
  121. $s .= '
  122. <div class="input-group">
  123. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off" style="'.($options ? $options : 'width:525px').'">
  124. <span class="input-group-btn">
  125. <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">选择链接 <span class="caret"></span></button>
  126. <ul class="dropdown-menu">
  127. <li><a href="javascript:" data-type="system" onclick="showLinkDialog(this);">系统菜单</a></li>
  128. <li><a href="javascript:" data-type="page" onclick="pageLinkDialog(this);">微页面</a></li>
  129. <li><a href="javascript:" data-type="article" onclick="articleLinkDialog(this)">文章及分类</a></li>
  130. <li><a href="javascript:" data-type="news" onclick="newsLinkDialog(this)">图文回复</a></li>
  131. <li><a href="javascript:" data-type="map" onclick="mapLinkDialog(this)">一键导航</a></li>
  132. <li><a href="javascript:" data-type="phone" onclick="phoneLinkDialog(this)">一键拨号</a></li>
  133. </ul>
  134. </span>
  135. </div>
  136. ';
  137. return $s;
  138. }
  139. function tpl_form_module_link($name) {
  140. $s = '';
  141. if (!defined('TPL_INIT_module')) {
  142. $s = '
  143. <script type="text/javascript">
  144. function showModuleLink(elm) {
  145. util.showModuleLink(function(href, permission) {
  146. var ipt = $(elm).parent().prev();
  147. var ipts = $(elm).parent().prev().prev();
  148. ipt.val(href);
  149. ipts.val(permission);
  150. });
  151. }
  152. </script>';
  153. define('TPL_INIT_module', true);
  154. }
  155. $s .= '
  156. <div class="input-group">
  157. <input type="text" class="form-control" name="permission" style="display: none">
  158. <input type="text" class="form-control" name="'.$name.'">
  159. <span class="input-group-btn">
  160. <a href="javascript:" class="btn btn-default" onclick="showModuleLink(this)">选择链接</a>
  161. </span>
  162. </div>
  163. ';
  164. return $s;
  165. }
  166. function tpl_form_field_emoji($name, $value = '') {
  167. $s = '';
  168. if (!defined('TPL_INIT_EMOJI')) {
  169. $s = '
  170. <script type="text/javascript">
  171. function showEmojiDialog(elm) {
  172. var btn = $(elm);
  173. var spview = btn.parent().prev();
  174. var ipt = spview.prev();
  175. if(!ipt.val()){
  176. spview.css("display","none");
  177. }
  178. util.emojiBrowser(function(emoji){
  179. ipt.val("\\\" + emoji.find("span").text().replace("+", "").toLowerCase());
  180. spview.show();
  181. spview.find("span").removeClass().addClass(emoji.find("span").attr("class"));
  182. });
  183. }
  184. </script>';
  185. define('TPL_INIT_EMOJI', true);
  186. }
  187. $s .= '
  188. <div class="input-group" style="width: 500px;">
  189. <input type="text" value="' . $value . '" name="' . $name . '" class="form-control" autocomplete="off">
  190. <span class="input-group-addon" style="display:none"><span></span></span>
  191. <span class="input-group-btn">
  192. <button class="btn btn-default" type="button" onclick="showEmojiDialog(this);">选择表情</button>
  193. </span>
  194. </div>
  195. ';
  196. return $s;
  197. }
  198. function tpl_form_field_color($name, $value = '') {
  199. $s = '';
  200. if (!defined('TPL_INIT_COLOR')) {
  201. $s = '
  202. <script type="text/javascript">
  203. $(function(){
  204. $(".colorpicker").each(function(){
  205. var elm = this;
  206. util.colorpicker(elm, function(color){
  207. $(elm).parent().prev().prev().val(color.toHexString());
  208. $(elm).parent().prev().css("background-color", color.toHexString());
  209. });
  210. });
  211. $(".colorclean").click(function(){
  212. $(this).parent().prev().prev().val("");
  213. $(this).parent().prev().css("background-color", "#FFF");
  214. });
  215. });
  216. </script>';
  217. define('TPL_INIT_COLOR', true);
  218. }
  219. $s .= '
  220. <div class="row row-fix">
  221. <div class="col-xs-8 col-sm-8" style="padding-right:0;">
  222. <div class="input-group">
  223. <input class="form-control" type="text" name="'.$name.'" placeholder="请选择颜色" value="'.$value.'">
  224. <span class="input-group-addon" style="width:35px;border-left:none;background-color:'.$value.'"></span>
  225. <span class="input-group-btn">
  226. <button class="btn btn-default colorpicker" type="button">选择颜色 <i class="fa fa-caret-down"></i></button>
  227. <button class="btn btn-default colorclean" type="button"><span><i class="fa fa-remove"></i></span></button>
  228. </span>
  229. </div>
  230. </div>
  231. </div>
  232. ';
  233. return $s;
  234. }
  235. function tpl_form_field_icon($name, $value='') {
  236. if(empty($value)){
  237. $value = 'fa fa-external-link';
  238. }
  239. $s = '';
  240. if (!defined('TPL_INIT_ICON')) {
  241. $s = '
  242. <script type="text/javascript">
  243. function showIconDialog(elm) {
  244. var btn = $(elm);
  245. var spview = btn.parent().prev();
  246. var ipt = spview.prev();
  247. if(!ipt.val()){
  248. spview.css("display","none");
  249. }
  250. util.iconBrowser(function(ico){
  251. ipt.val(ico);
  252. spview.show();
  253. spview.find("i").attr("class","");
  254. spview.find("i").addClass("fa").addClass(ico);
  255. });
  256. }
  257. </script>';
  258. define('TPL_INIT_ICON', true);
  259. }
  260. $s .= '
  261. <div class="input-group" style="width: 300px;">
  262. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off">
  263. <span class="input-group-addon"><i class="'.$value.' fa"></i></span>
  264. <span class="input-group-btn">
  265. <button class="btn btn-default" type="button" onclick="showIconDialog(this);">选择图标</button>
  266. </span>
  267. </div>
  268. ';
  269. return $s;
  270. }
  271. function tpl_form_field_image($name, $value = '', $default = '', $options = array()) {
  272. global $_W;
  273. if (empty($default)) {
  274. $default = './resource/images/nopic.jpg';
  275. }
  276. $val = $default;
  277. if (!empty($value)) {
  278. $val = tomedia($value);
  279. }
  280. if (defined('SYSTEM_WELCOME_MODULE')) {
  281. $options['uniacid'] = 0;
  282. }
  283. if (!empty($options['global'])) {
  284. $options['global'] = true;
  285. $val = to_global_media(empty($value) ? $default : $value);
  286. } else {
  287. $options['global'] = false;
  288. }
  289. if (empty($options['class_extra'])) {
  290. $options['class_extra'] = '';
  291. }
  292. if (isset($options['dest_dir']) && !empty($options['dest_dir'])) {
  293. if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) {
  294. exit('图片上传目录错误,只能指定最多两级目录,如: "we7_store","we7_store/d1"');
  295. }
  296. }
  297. $options['direct'] = true;
  298. $options['multiple'] = false;
  299. if (isset($options['thumb'])) {
  300. $options['thumb'] = !empty($options['thumb']);
  301. }
  302. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024;
  303. $s = '';
  304. if (!defined('TPL_INIT_IMAGE')) {
  305. $s = '
  306. <script type="text/javascript">
  307. function showImageDialog(elm, opts, options) {
  308. require(["util"], function(util){
  309. var btn = $(elm);
  310. var ipt = btn.parent().prev();
  311. var val = ipt.val();
  312. var img = ipt.parent().next().children();
  313. options = '.str_replace('"', '\'', json_encode($options)).';
  314. util.image(val, function(url){
  315. if(url.url){
  316. if(img.length > 0){
  317. img.get(0).src = url.url;
  318. }
  319. ipt.val(url.attachment);
  320. ipt.attr("filename",url.filename);
  321. ipt.attr("url",url.url);
  322. }
  323. if(url.media_id){
  324. if(img.length > 0){
  325. img.get(0).src = url.url;
  326. }
  327. ipt.val(url.media_id);
  328. }
  329. }, options);
  330. });
  331. }
  332. function deleteImage(elm){
  333. $(elm).prev().attr("src", "./resource/images/nopic.jpg");
  334. $(elm).parent().prev().find("input").val("");
  335. }
  336. </script>';
  337. define('TPL_INIT_IMAGE', true);
  338. }
  339. $s .= '
  340. <div class="input-group ' . $options['class_extra'] . '">
  341. <input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
  342. <span class="input-group-btn">
  343. <button class="btn btn-default" type="button" onclick="showImageDialog(this);">选择图片</button>
  344. </span>
  345. </div>
  346. <div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
  347. <img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
  348. <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
  349. </div>';
  350. return $s;
  351. }
  352. function tpl_form_field_multi_image($name, $value = array(), $options = array()) {
  353. global $_W;
  354. $options['multiple'] = true;
  355. $options['direct'] = false;
  356. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024;
  357. if (isset($options['dest_dir']) && !empty($options['dest_dir'])) {
  358. if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) {
  359. exit('图片上传目录错误,只能指定最多两级目录,如: "we7_store","we7_store/d1"');
  360. }
  361. }
  362. $s = '';
  363. if (!defined('TPL_INIT_MULTI_IMAGE')) {
  364. $s = '
  365. <script type="text/javascript">
  366. function uploadMultiImage(elm) {
  367. var name = $(elm).next().val();
  368. util.image( "", function(urls){
  369. $.each(urls, function(idx, url){
  370. $(elm).parent().parent().next().append(\'<div class="multi-item"><img onerror="this.src=\\\'./resource/images/nopic.jpg\\\'; this.title=\\\'图片未找到.\\\'" src="\'+url.url+\'" class="img-responsive img-thumbnail"><input type="hidden" name="\'+name+\'[]" value="\'+url.attachment+\'"><em class="close" title="删除这张图片" onclick="deleteMultiImage(this)">×</em></div>\');
  371. });
  372. }, ' . json_encode($options) . ');
  373. }
  374. function deleteMultiImage(elm){
  375. $(elm).parent().remove();
  376. }
  377. </script>';
  378. define('TPL_INIT_MULTI_IMAGE', true);
  379. }
  380. $s .= <<<EOF
  381. <div class="input-group">
  382. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传图片" autocomplete="off">
  383. <span class="input-group-btn">
  384. <button class="btn btn-default" type="button" onclick="uploadMultiImage(this);">选择图片</button>
  385. <input type="hidden" value="{$name}" />
  386. </span>
  387. </div>
  388. <div class="input-group multi-img-details">
  389. EOF;
  390. if (is_array($value) && count($value) > 0) {
  391. foreach ($value as $row) {
  392. $s .= '
  393. <div class="multi-item">
  394. <img src="' . tomedia($row) . '" onerror="this.src=\'./resource/images/nopic.jpg\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail">
  395. <input type="hidden" name="' . $name . '[]" value="' . $row . '" >
  396. <em class="close" title="删除这张图片" onclick="deleteMultiImage(this)">×</em>
  397. </div>';
  398. }
  399. }
  400. $s .= '</div>';
  401. return $s;
  402. }
  403. function tpl_form_field_audio($name, $value = '', $options = array()) {
  404. if (!is_array($options)) {
  405. $options = array();
  406. }
  407. $options['direct'] = true;
  408. $options['multiple'] = false;
  409. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  410. $s = '';
  411. if (!defined('TPL_INIT_AUDIO')) {
  412. $s = '
  413. <script type="text/javascript">
  414. function showAudioDialog(elm, base64options, options) {
  415. require(["util"], function(util){
  416. var btn = $(elm);
  417. var ipt = btn.parent().prev();
  418. var val = ipt.val();
  419. util.audio(val, function(url){
  420. if(url && url.attachment && url.url){
  421. btn.prev().show();
  422. ipt.val(url.attachment);
  423. ipt.attr("filename",url.filename);
  424. ipt.attr("url",url.url);
  425. setAudioPlayer();
  426. }
  427. if(url && url.media_id){
  428. ipt.val(url.media_id);
  429. }
  430. }, "" , ' . json_encode($options) . ');
  431. });
  432. }
  433. function setAudioPlayer(){
  434. require(["jquery.jplayer"], function(){
  435. $(function(){
  436. $(".audio-player").each(function(){
  437. $(this).prev().find("button").eq(0).click(function(){
  438. var src = $(this).parent().prev().val();
  439. if($(this).find("i").hasClass("fa-stop")) {
  440. $(this).parent().parent().next().jPlayer("stop");
  441. } else {
  442. if(src) {
  443. $(this).parent().parent().next().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  444. }
  445. }
  446. });
  447. });
  448. $(".audio-player").jPlayer({
  449. playing: function() {
  450. $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
  451. },
  452. pause: function (event) {
  453. $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
  454. },
  455. swfPath: "resource/components/jplayer",
  456. supplied: "mp3"
  457. });
  458. $(".audio-player-media").each(function(){
  459. $(this).next().find(".audio-player-play").css("display", $(this).val() == "" ? "none" : "");
  460. });
  461. });
  462. });
  463. }
  464. setAudioPlayer();
  465. </script>';
  466. echo $s;
  467. define('TPL_INIT_AUDIO', true);
  468. }
  469. $s .= '
  470. <div class="input-group">
  471. <input type="text" value="' . $value . '" name="' . $name . '" class="form-control audio-player-media" autocomplete="off" ' . ($options['extras']['text'] ? $options['extras']['text'] : '') . '>
  472. <span class="input-group-btn">
  473. <button class="btn btn-default audio-player-play" type="button" style="display:none;"><i class="fa fa-play"></i></button>
  474. <button class="btn btn-default" type="button" onclick="showAudioDialog(this, \'' . base64_encode(iserializer($options)) . '\',' . str_replace('"', '\'', json_encode($options)) . ');">选择媒体文件</button>
  475. </span>
  476. </div>
  477. <div class="input-group audio-player"></div>';
  478. return $s;
  479. }
  480. function tpl_form_field_multi_audio($name, $value = array(), $options = array()) {
  481. $s = '';
  482. $options['direct'] = false;
  483. $options['multiple'] = true;
  484. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  485. if (!defined('TPL_INIT_MULTI_AUDIO')) {
  486. $s .= '
  487. <script type="text/javascript">
  488. function showMultiAudioDialog(elm, name) {
  489. require(["util"], function(util){
  490. var btn = $(elm);
  491. var ipt = btn.parent().prev();
  492. var val = ipt.val();
  493. util.audio(val, function(urls){
  494. $.each(urls, function(idx, url){
  495. var obj = $(\'<div class="multi-audio-item" style="height: 40px; position:relative; float: left; margin-right: 18px;"><div class="multi-audio-player"></div><div class="input-group"><input type="text" class="form-control" readonly value="\' + url.attachment + \'" /><div class="input-group-btn"><button class="btn btn-default" type="button"><i class="fa fa-play"></i></button><button class="btn btn-default" onclick="deleteMultiAudio(this)" type="button"><i class="fa fa-remove"></i></button></div></div><input type="hidden" name="\'+name+\'[]" value="\'+url.attachment+\'"></div>\');
  496. $(elm).parent().parent().next().append(obj);
  497. setMultiAudioPlayer(obj);
  498. });
  499. }, ' . json_encode($options) . ');
  500. });
  501. }
  502. function deleteMultiAudio(elm){
  503. $(elm).parent().parent().parent().remove();
  504. }
  505. function setMultiAudioPlayer(elm){
  506. require(["jquery.jplayer"], function(){
  507. $(".multi-audio-player",$(elm)).next().find("button").eq(0).click(function(){
  508. var src = $(this).parent().prev().val();
  509. if($(this).find("i").hasClass("fa-stop")) {
  510. $(this).parent().parent().prev().jPlayer("stop");
  511. } else {
  512. if(src) {
  513. $(this).parent().parent().prev().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  514. }
  515. }
  516. });
  517. $(".multi-audio-player",$(elm)).jPlayer({
  518. playing: function() {
  519. $(this).next().find("i").eq(0).removeClass("fa-play").addClass("fa-stop");
  520. },
  521. pause: function (event) {
  522. $(this).next().find("i").eq(0).removeClass("fa-stop").addClass("fa-play");
  523. },
  524. swfPath: "resource/components/jplayer",
  525. supplied: "mp3"
  526. });
  527. });
  528. }
  529. </script>';
  530. define('TPL_INIT_MULTI_AUDIO', true);
  531. }
  532. $s .= '
  533. <div class="input-group">
  534. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传音乐" autocomplete="off">
  535. <span class="input-group-btn">
  536. <button class="btn btn-default" type="button" onclick="showMultiAudioDialog(this,\'' . $name . '\');">选择音乐</button>
  537. </span>
  538. </div>
  539. <div class="input-group multi-audio-details clear-fix" style="margin-top:.5em;">';
  540. if (!empty($value) && !is_array($value)) {
  541. $value = array($value);
  542. }
  543. if (is_array($value) && count($value) > 0) {
  544. $n = 0;
  545. foreach ($value as $row) {
  546. $m = random(8);
  547. $s .= '
  548. <div class="multi-audio-item multi-audio-item-' . $n . '-' . $m . '" style="height: 40px; position:relative; float: left; margin-right: 18px;">
  549. <div class="multi-audio-player"></div>
  550. <div class="input-group">
  551. <input type="text" class="form-control" value="' . $row . '" readonly/>
  552. <div class="input-group-btn">
  553. <button class="btn btn-default" type="button"><i class="fa fa-play"></i></button>
  554. <button class="btn btn-default" onclick="deleteMultiAudio(this)" type="button"><i class="fa fa-remove"></i></button>
  555. </div>
  556. </div>
  557. <input type="hidden" name="' . $name . '[]" value="' . $row . '">
  558. </div>
  559. <script language="javascript">setMultiAudioPlayer($(".multi-audio-item-' . $n . '-' . $m . '"));</script>';
  560. $n++;
  561. }
  562. }
  563. $s .= '
  564. </div>';
  565. return $s;
  566. }
  567. function tpl_form_field_video($name, $value = '', $options = array()) {
  568. if(!is_array($options)){
  569. $options = array();
  570. }
  571. if (!is_array($options)) {
  572. $options = array();
  573. }
  574. $options['direct'] = true;
  575. $options['multi'] = false;
  576. $options['type'] = 'video';
  577. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  578. $s = '';
  579. if (!defined('TPL_INIT_VIDEO')) {
  580. $s = '
  581. <script type="text/javascript">
  582. function showVideoDialog(elm, options) {
  583. require(["util"], function(util){
  584. var btn = $(elm);
  585. var ipt = btn.parent().prev();
  586. var val = ipt.val();
  587. util.audio(val, function(url){
  588. if(url && url.attachment && url.url){
  589. btn.prev().show();
  590. ipt.val(url.attachment);
  591. ipt.attr("filename",url.filename);
  592. ipt.attr("url",url.url);
  593. }
  594. if(url && url.media_id){
  595. ipt.val(url.media_id);
  596. }
  597. }, '.json_encode($options).');
  598. });
  599. }
  600. </script>';
  601. echo $s;
  602. define('TPL_INIT_VIDEO', true);
  603. }
  604. $s .= '
  605. <div class="input-group">
  606. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  607. <span class="input-group-btn">
  608. <button class="btn btn-default" type="button" onclick="showVideoDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  609. </span>
  610. </div>';
  611. return $s;
  612. }
  613. function tpl_form_field_wechat_image($name, $value = '', $default = '', $options = array()) {
  614. global $_W;
  615. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  616. $options['account_error'] = 1;
  617. } else {
  618. $options['acid'] = $_W['acid'];
  619. }
  620. if(empty($default)) {
  621. $default = './resource/images/nopic.jpg';
  622. }
  623. $val = $default;
  624. if (!empty($value)) {
  625. $media_data = (array)media2local($value, true);
  626. $val = $media_data['attachment'];
  627. }
  628. if (empty($options['class_extra'])) {
  629. $options['class_extra'] = '';
  630. }
  631. $options['direct'] = true;
  632. $options['multiple'] = false;
  633. $options['type'] = empty($options['type']) ? 'image' : $options['type'];
  634. $s = '';
  635. if (!defined('TPL_INIT_WECHAT_IMAGE')) {
  636. $s = '
  637. <script type="text/javascript">
  638. function showWechatImageDialog(elm, options) {
  639. require(["util"], function(util){
  640. var btn = $(elm);
  641. var ipt = btn.parent().prev();
  642. var val = ipt.val();
  643. var img = ipt.parent().next().children();
  644. util.wechat_image(val, function(url){
  645. if(url.media_id){
  646. if(img.length > 0){
  647. img.get(0).src = url.url;
  648. }
  649. ipt.val(url.media_id);
  650. }
  651. }, options);
  652. });
  653. }
  654. function deleteImage(elm){
  655. $(elm).prev().attr("src", "./resource/images/nopic.jpg");
  656. $(elm).parent().prev().find("input").val("");
  657. }
  658. </script>';
  659. define('TPL_INIT_WECHAT_IMAGE', true);
  660. }
  661. $s .= '
  662. <div class="input-group ' . $options['class_extra'] . '">
  663. <input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
  664. <span class="input-group-btn">
  665. <button class="btn btn-default" type="button" onclick="showWechatImageDialog(this, ' . str_replace('"', '\'', json_encode($options)) . ');">选择图片</button>
  666. </span>
  667. </div>';
  668. $s .=
  669. '<div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
  670. <img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
  671. <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
  672. </div>';
  673. if (!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)) {
  674. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  675. }
  676. return $s;
  677. }
  678. function tpl_form_field_wechat_multi_image($name, $value = '', $default = '', $options = array()) {
  679. global $_W;
  680. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  681. $options['account_error'] = 1;
  682. } else {
  683. $options['acid'] = $_W['acid'];
  684. }
  685. if(empty($default)) {
  686. $default = './resource/images/nopic.jpg';
  687. }
  688. if(empty($options['class_extra'])) {
  689. $options['class_extra'] = '';
  690. }
  691. $options['direct'] = false;
  692. $options['multiple'] = true;
  693. $options['type'] = empty($options['type']) ? 'image' : $options['type'];
  694. $s = '';
  695. if (!defined('TPL_INIT_WECHAT_MULTI_IMAGE')) {
  696. $s = '
  697. <script type="text/javascript">
  698. function uploadWechatMultiImage(elm) {
  699. var name = $(elm).next().val();
  700. util.wechat_image("", function(urls){
  701. $.each(urls, function(idx, url){
  702. $(elm).parent().parent().next().append(\'<div class="multi-item"><img onerror="this.src=\\\'./resource/images/nopic.jpg\\\'; this.title=\\\'图片未找到.\\\'" src="\'+url.url+\'" class="img-responsive img-thumbnail"><input type="hidden" name="\'+name+\'[]" value="\'+url.media_id+\'"><em class="close" title="删除这张图片" onclick="deleteWechatMultiImage(this)">×</em></div>\');
  703. });
  704. }, '.json_encode($options).');
  705. }
  706. function deleteWechatMultiImage(elm){
  707. $(elm).parent().remove();
  708. }
  709. </script>';
  710. define('TPL_INIT_WECHAT_MULTI_IMAGE', true);
  711. }
  712. $s .= <<<EOF
  713. <div class="input-group">
  714. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传图片" autocomplete="off">
  715. <span class="input-group-btn">
  716. <button class="btn btn-default" type="button" onclick="uploadWechatMultiImage(this);">选择图片</button>
  717. <input type="hidden" value="{$name}" />
  718. </span>
  719. </div>
  720. <div class="input-group multi-img-details">
  721. EOF;
  722. if (is_array($value) && count($value)>0) {
  723. foreach ($value as $row) {
  724. $s .='
  725. <div class="multi-item">
  726. <img src="'.media2local($row).'" onerror="this.src=\'./resource/images/nopic.jpg\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail">
  727. <input type="hidden" name="'.$name.'[]" value="'.$row.'" >
  728. <em class="close" title="删除这张图片" onclick="deleteWechatMultiImage(this)">×</em>
  729. </div>';
  730. }
  731. }
  732. $s .= '</div>';
  733. return $s;
  734. }
  735. function tpl_form_field_wechat_voice($name, $value = '', $options = array()) {
  736. global $_W;
  737. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  738. $options['account_error'] = 1;
  739. } else {
  740. $options['acid'] = $_W['acid'];
  741. }
  742. if(!empty($value)) {
  743. $media_data = (array)media2local($value, true);
  744. $val = $media_data['attachment'];
  745. }
  746. if(!is_array($options)){
  747. $options = array();
  748. }
  749. $options['direct'] = true;
  750. $options['multiple'] = false;
  751. $options['type'] = 'voice';
  752. $s = '';
  753. if (!defined('TPL_INIT_WECHAT_VOICE')) {
  754. $s = '
  755. <script type="text/javascript">
  756. function showWechatVoiceDialog(elm, options) {
  757. require(["util"], function(util){
  758. var btn = $(elm);
  759. var ipt = btn.parent().prev();
  760. var val = ipt.val();
  761. util.wechat_audio(val, function(url){
  762. if(url && url.media_id && url.url){
  763. btn.prev().show();
  764. ipt.val(url.media_id);
  765. ipt.attr("media_id",url.media_id);
  766. ipt.attr("url",url.url);
  767. setWechatAudioPlayer();
  768. }
  769. if(url && url.media_id){
  770. ipt.val(url.media_id);
  771. }
  772. } , '.json_encode($options).');
  773. });
  774. }
  775. function setWechatAudioPlayer(){
  776. require(["jquery.jplayer"], function(){
  777. $(function(){
  778. $(".audio-player").each(function(){
  779. $(this).prev().find("button").eq(0).click(function(){
  780. var src = $(this).parent().prev().attr("url");
  781. if($(this).find("i").hasClass("fa-stop")) {
  782. $(this).parent().parent().next().jPlayer("stop");
  783. } else {
  784. if(src) {
  785. $(this).parent().parent().next().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  786. }
  787. }
  788. });
  789. });
  790. $(".audio-player").jPlayer({
  791. playing: function() {
  792. $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
  793. },
  794. pause: function (event) {
  795. $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
  796. },
  797. swfPath: "resource/components/jplayer",
  798. supplied: "mp3"
  799. });
  800. $(".audio-player-media").each(function(){
  801. $(this).next().find(".audio-player-play").css("display", $(this).val() == "" ? "none" : "");
  802. });
  803. });
  804. });
  805. }
  806. setWechatAudioPlayer();
  807. </script>';
  808. echo $s;
  809. define('TPL_INIT_WECHAT_VOICE', true);
  810. }
  811. $s .= '
  812. <div class="input-group">
  813. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control audio-player-media" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  814. <span class="input-group-btn">
  815. <button class="btn btn-default audio-player-play" type="button" style="display:none"><i class="fa fa-play"></i></button>
  816. <button class="btn btn-default" type="button" onclick="showWechatVoiceDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  817. </span>
  818. </div>
  819. <div class="input-group audio-player">
  820. </div>';
  821. if(!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)){
  822. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  823. }
  824. return $s;
  825. }
  826. function tpl_form_field_wechat_video($name, $value = '', $options = array()) {
  827. global $_W;
  828. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  829. $options['account_error'] = 1;
  830. } else {
  831. $options['acid'] = $_W['acid'];
  832. }
  833. if(!empty($value)) {
  834. $media_data = (array)media2local($value, true);
  835. $val = $media_data['attachment'];
  836. }
  837. if(!is_array($options)){
  838. $options = array();
  839. }
  840. if(empty($options['tabs'])){
  841. $options['tabs'] = array('video'=>'active', 'browser'=>'');
  842. }
  843. $options = array_elements(array('tabs','global','dest_dir', 'acid', 'error'), $options);
  844. $options['direct'] = true;
  845. $options['multi'] = false;
  846. $options['type'] = 'video';
  847. $s = '';
  848. if (!defined('TPL_INIT_WECHAT_VIDEO')) {
  849. $s = '
  850. <script type="text/javascript">
  851. function showWechatVideoDialog(elm, options) {
  852. require(["util"], function(util){
  853. var btn = $(elm);
  854. var ipt = btn.parent().prev();
  855. var val = ipt.val();
  856. util.wechat_audio(val, function(url){
  857. if(url && url.media_id && url.url){
  858. btn.prev().show();
  859. ipt.val(url.media_id);
  860. ipt.attr("media_id",url.media_id);
  861. ipt.attr("url",url.url);
  862. }
  863. if(url && url.media_id){
  864. ipt.val(url.media_id);
  865. }
  866. }, '.json_encode($options).');
  867. });
  868. }
  869. </script>';
  870. echo $s;
  871. define('TPL_INIT_WECHAT_VIDEO', true);
  872. }
  873. $s .= '
  874. <div class="input-group">
  875. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  876. <span class="input-group-btn">
  877. <button class="btn btn-default" type="button" onclick="showWechatVideoDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  878. </span>
  879. </div>
  880. <div class="input-group audio-player">
  881. </div>';
  882. if(!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)){
  883. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  884. }
  885. return $s;
  886. }
  887. function tpl_form_field_location_category($name, $values = array(), $del = false) {
  888. $html = '';
  889. if (!defined('TPL_INIT_LOCATION_CATEGORY')) {
  890. $html .= '
  891. <script type="text/javascript">
  892. require(["location"], function(loc){
  893. $(".tpl-location-container").each(function(){
  894. var elms = {};
  895. elms.cate = $(this).find(".tpl-cate")[0];
  896. elms.sub = $(this).find(".tpl-sub")[0];
  897. elms.clas = $(this).find(".tpl-clas")[0];
  898. var vals = {};
  899. vals.cate = $(elms.cate).attr("data-value");
  900. vals.sub = $(elms.sub).attr("data-value");
  901. vals.clas = $(elms.clas).attr("data-value");
  902. loc.render(elms, vals, {withTitle: true});
  903. });
  904. });
  905. </script>';
  906. define('TPL_INIT_LOCATION_CATEGORY', true);
  907. }
  908. if (empty($values) || !is_array($values)) {
  909. $values = array('cate'=>'','sub'=>'','clas'=>'');
  910. }
  911. if(empty($values['cate'])) {
  912. $values['cate'] = '';
  913. }
  914. if(empty($values['sub'])) {
  915. $values['sub'] = '';
  916. }
  917. if(empty($values['clas'])) {
  918. $values['clas'] = '';
  919. }
  920. $html .= '
  921. <div class="row row-fix tpl-location-container">
  922. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  923. <select name="' . $name . '[cate]" data-value="' . $values['cate'] . '" class="form-control tpl-cate">
  924. </select>
  925. </div>
  926. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  927. <select name="' . $name . '[sub]" data-value="' . $values['sub'] . '" class="form-control tpl-sub">
  928. </select>
  929. </div>
  930. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  931. <select name="' . $name . '[clas]" data-value="' . $values['clas'] . '" class="form-control tpl-clas">
  932. </select>
  933. </div>';
  934. if($del) {
  935. $html .='
  936. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3" style="padding-top:5px">
  937. <a title="删除" onclick="$(this).parents(\'.tpl-location-container\').remove();return false;"><i class="fa fa-times-circle"></i></a>
  938. </div>
  939. </div>';
  940. } else {
  941. $html .= '</div>';
  942. }
  943. return $html;
  944. }
  945. function tpl_ueditor($id, $value = '', $options = array()) {
  946. $s = '';
  947. $options['height'] = empty($options['height']) ? 200 : $options['height'];
  948. $options['allow_upload_video'] = isset($options['allow_upload_video']) ? $options['allow_upload_video'] : true;
  949. $s .= !empty($id) ? "<textarea id=\"{$id}\" name=\"{$id}\" type=\"text/plain\" style=\"height:{$options['height']}px;\">{$value}</textarea>" : '';
  950. $s .= "
  951. <script type=\"text/javascript\">
  952. require(['util'], function(util){
  953. util.editor('" . ($id ? $id : "") . "', {
  954. height : {$options['height']},
  955. dest_dir : '" .($options['dest_dir'] ? $options['dest_dir'] : "") . "',
  956. image_limit : " . (intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024) . ",
  957. allow_upload_video : " . ($options['allow_upload_video'] ? 'true' : 'false') . ",
  958. audio_limit : " . (intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024) . ",
  959. callback : ''
  960. });
  961. });
  962. </script>";
  963. return $s;
  964. }
  965. function tpl_edit_sms($name, $value, $uniacid, $url, $num) {
  966. $s = '
  967. <div class="input-group">
  968. <input type="text" name="'.$name.'" id="balance" readonly value="'.$value.'" class="form-control" autocomplete="off">
  969. <span class="input-group-btn">
  970. <button type="button" class="btn btn-default" data-toggle="modal" data-target="#edit_sms">编辑短信条数</button>
  971. </span>
  972. </div>
  973. <span class="help-block">请填写短信剩余条数,必须为整数。</span>
  974. <div class="modal fade" id="edit_sms" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  975. <div class="modal-dialog" role="document">
  976. <div class="modal-content">
  977. <div class="modal-header">
  978. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  979. <h4 class="modal-title" id="">修改短信条数</h4>
  980. </div>
  981. <div class="modal-body" style="height: 100px;">
  982. <div class="form-group">
  983. <label class="col-xs-12 col-sm-5 col-md-6 col-lg-3 control-label">短信条数</label>
  984. <div class="col-sm-6 col-xs-12 col-md-7">
  985. <div class="input-group" style="width: 180px;">
  986. <div class="input-group-btn">
  987. <button type="button" class="btn btn-defaultt label-success" id="edit_add">+</button>
  988. </div>
  989. <!--<span class="input-group-addon label-danger" id="edit_alert" style="width: 10px;">+ </span>-->
  990. <input type="text" class="form-control" id="edit_num" value="+">
  991. <div class="input-group-btn">
  992. <button type="button" class="btn btn-default" id="edit_minus">-</button>
  993. </div>
  994. </div>
  995. <div class="help-block">点击加号或减号切换修改短信条数方式<br>最多可添加<span id="count_sms">'.$num.'</span>条短信</div>
  996. </div>
  997. </div>
  998. </div>
  999. <div class="modal-footer">
  1000. <button type="button" id="edit_sms_sub" class="btn btn-primary">保存</button>
  1001. </div>
  1002. </div>
  1003. </div>
  1004. </div>
  1005. <script>
  1006. var status = \'add\';
  1007. $(\'#edit_add\').click(function() {
  1008. status = \'add\';
  1009. var sign = status == \'add\' ? \'+\' : \'-\';
  1010. var edit_num = $(\'#edit_num\').val();
  1011. if (edit_num == \'\') {
  1012. $(\'#edit_num\').val(sign)
  1013. return;
  1014. }
  1015. if (isNaN(edit_num.substr(1)) || edit_num.substr(1) == \'\') {
  1016. edit_num = \'\';
  1017. }
  1018. $(\'#edit_num\').val(\'+\'+Math.abs(edit_num));
  1019. if (edit_num == \'\') {
  1020. $(\'#edit_num\').val(sign);
  1021. }
  1022. $(\'#edit_add\').attr(\'class\', \'btn btn-defaultt label-success\');
  1023. $(\'#edit_minus\').attr(\'class\', \'btn btn-default\');
  1024. });
  1025. $(\'#edit_num\').keyup(function() {
  1026. var sign = status == \'add\' ? \'+\' : \'-\';
  1027. if ($(\'#edit_num\').val() == \'\') {
  1028. return ;
  1029. }
  1030. if (isNaN($(\'#edit_num\').val()) && $(\'#edit_num\').val() != sign) {
  1031. $(\'#edit_num\').val(\'\');
  1032. return;
  1033. }
  1034. if ($(\'#edit_num\').val().indexOf(sign) < 0) {
  1035. var val = parseInt(Math.abs($(\'#edit_num\').val()));
  1036. if (val == 0) {
  1037. $(\'#edit_num\').val(sign);
  1038. } else {
  1039. $(\'#edit_num\').val(sign + val);
  1040. }
  1041. }
  1042. });
  1043. $(\'#edit_minus\').click(function() {
  1044. status = \'minus\';
  1045. var sign = status == \'add\' ? \'+\' : \'-\';
  1046. var edit_num = $(\'#edit_num\').val();
  1047. if (edit_num == \'\') {
  1048. $(\'#edit_num\').val(sign)
  1049. return;
  1050. }
  1051. if (isNaN(edit_num.substr(1)) || edit_num.substr(1) == \'\') {
  1052. edit_num = \'\';
  1053. }
  1054. $(\'#edit_num\').val(\'-\'+Math.abs(edit_num));
  1055. if (edit_num == \'\') {
  1056. $(\'#edit_num\').val(sign);
  1057. }
  1058. $(\'#edit_minus\').attr(\'class\', \'btn btn-defaultt label-danger\');
  1059. $(\'#edit_add\').attr(\'class\', \'btn btn-default\');
  1060. });
  1061. $(\'#edit_sms_sub\').click(function () {
  1062. var edit_num = $(\'#edit_num\').val() == \'\' ? 0 : Math.abs(parseInt($(\'#edit_num\').val()));
  1063. var uniacid = '.$uniacid.';
  1064. $.post(\''.$url.'\', {\'balance\' : edit_num, \'uniacid\' : uniacid, \'status\' : status}, function(data) {
  1065. var data = $.parseJSON(data);
  1066. $(\'#count_sms\').html(data.message.message.count);
  1067. if (data.message.errno > 0) {
  1068. $(\'#balance\').val(data.message.message.num);
  1069. $(\'#edit_sms\').modal(\'toggle\');
  1070. } else {
  1071. util.message(\'您现有短信数量为0,请联系服务商购买短信\');
  1072. $(\'#edit_sms\').modal(\'toggle\');
  1073. }
  1074. $(\'#edit_num\').val(\'\');
  1075. $(\'#edit_add\').trigger(\'click\');
  1076. });
  1077. });
  1078. </script>
  1079. ';
  1080. return $s;
  1081. }
  1082. function tpl_coupon_colors($name, $value = 'Color082') {
  1083. load()->model('activity');
  1084. $options = activity_coupon_colors();
  1085. empty($name) && ($name = 'coupon_color');
  1086. if (!defined('TPL_INIT_COUPON_COLOR')) {
  1087. $html = '
  1088. <script type="text/javascript">
  1089. function showCouponColor(eml) {
  1090. var dropdown = $(eml).parent().parent().next();
  1091. dropdown.show();
  1092. $(document).click(function(){
  1093. dropdown.hide();
  1094. });
  1095. $(".coupon-color").click(function(e){
  1096. e.stopPropagation();
  1097. });
  1098. $(".dropdown-menu li").click(function(){
  1099. $(eml).parent().prev().css("background", $(this).attr("data-color"));
  1100. $(eml).parent().prev().css("border-color", $(this).attr("data-color"));
  1101. $(eml).parent().prev().prev().prev().val($(this).attr("data-name"));
  1102. $(eml).parent().prev().prev().val($(this).attr("data-color"));
  1103. dropdown.hide();
  1104. $(document).unbind("click");
  1105. $(".dropdown-menu li, .coupon-color").unbind("click");
  1106. });
  1107. }
  1108. </script>';
  1109. define('TPL_INIT_COUPON_COLOR', true);
  1110. }
  1111. $html .= '
  1112. <div class="col-sm-9 col-xs-12 coupon-color" style="position: relative;width:200px;">
  1113. <div class="input-group" style="width:200px;">
  1114. <input type="text" class="form-control" name="'.$name.'" value="'.$value.'"/>
  1115. <input type="hidden" name="'.$name.'-value" class="form-control" value="'.$value.'"/>
  1116. <span class="input-group-addon" style="width:35px;background:'.$options[$value].'"></span>
  1117. <span class="input-group-btn">
  1118. <button class="btn btn-default" type="button" onclick="showCouponColor(this);">选择颜色</button>
  1119. </span>
  1120. </div>
  1121. <div class="dropdown-menu" style="display:none;padding:6px 0 0 6px;width:185px;position: absolute;top:35px;left:15px">
  1122. <ul style="padding:0">
  1123. ';
  1124. if(!empty($options)) {
  1125. foreach($options as $colorname => $colorvalue) {
  1126. $html .= '<li data-name="'.$colorname.'" data-color="'.$colorvalue.'" style="padding: 0;margin-right:5px;margin-bottom:5px;width:30px;height:30px;background:'.$colorvalue.';float:left;list-style: none;"></li>';
  1127. }
  1128. }
  1129. $html .= '
  1130. </ul>
  1131. </div>
  1132. </div>
  1133. ';
  1134. return $html;
  1135. }