人人商城

tpl.func.php 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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 (!empty($options['global'])) {
  281. $options['global'] = true;
  282. } else {
  283. $options['global'] = false;
  284. }
  285. if (empty($options['class_extra'])) {
  286. $options['class_extra'] = '';
  287. }
  288. if (isset($options['dest_dir']) && !empty($options['dest_dir'])) {
  289. if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) {
  290. exit('图片上传目录错误,只能指定最多两级目录,如: "we7_store","we7_store/d1"');
  291. }
  292. }
  293. $options['direct'] = true;
  294. $options['multiple'] = false;
  295. if (isset($options['thumb'])) {
  296. $options['thumb'] = !empty($options['thumb']);
  297. }
  298. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024;
  299. $s = '';
  300. if (!defined('TPL_INIT_IMAGE')) {
  301. $s = '
  302. <script type="text/javascript">
  303. function showImageDialog(elm, opts, options) {
  304. require(["util"], function(util){
  305. var btn = $(elm);
  306. var ipt = btn.parent().prev();
  307. var val = ipt.val();
  308. var img = ipt.parent().next().children();
  309. options = '.str_replace('"', '\'', json_encode($options)).';
  310. util.image(val, function(url){
  311. if(url.url){
  312. if(img.length > 0){
  313. img.get(0).src = url.url;
  314. }
  315. ipt.val(url.attachment);
  316. ipt.attr("filename",url.filename);
  317. ipt.attr("url",url.url);
  318. }
  319. if(url.media_id){
  320. if(img.length > 0){
  321. img.get(0).src = "";
  322. }
  323. ipt.val(url.media_id);
  324. }
  325. }, options);
  326. });
  327. }
  328. function deleteImage(elm){
  329. $(elm).prev().attr("src", "./resource/images/nopic.jpg");
  330. $(elm).parent().prev().find("input").val("");
  331. }
  332. </script>';
  333. define('TPL_INIT_IMAGE', true);
  334. }
  335. $s .= '
  336. <div class="input-group ' . $options['class_extra'] . '">
  337. <input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
  338. <span class="input-group-btn">
  339. <button class="btn btn-default" type="button" onclick="showImageDialog(this);">选择图片</button>
  340. </span>
  341. </div>
  342. <div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
  343. <img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
  344. <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
  345. </div>';
  346. return $s;
  347. }
  348. function tpl_form_field_multi_image($name, $value = array(), $options = array()) {
  349. global $_W;
  350. $options['multiple'] = true;
  351. $options['direct'] = false;
  352. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024;
  353. if (isset($options['dest_dir']) && !empty($options['dest_dir'])) {
  354. if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) {
  355. exit('图片上传目录错误,只能指定最多两级目录,如: "we7_store","we7_store/d1"');
  356. }
  357. }
  358. $s = '';
  359. if (!defined('TPL_INIT_MULTI_IMAGE')) {
  360. $s = '
  361. <script type="text/javascript">
  362. function uploadMultiImage(elm) {
  363. var name = $(elm).next().val();
  364. util.image( "", function(urls){
  365. $.each(urls, function(idx, url){
  366. $(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>\');
  367. });
  368. }, ' . json_encode($options) . ');
  369. }
  370. function deleteMultiImage(elm){
  371. $(elm).parent().remove();
  372. }
  373. </script>';
  374. define('TPL_INIT_MULTI_IMAGE', true);
  375. }
  376. $s .= <<<EOF
  377. <div class="input-group">
  378. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传图片" autocomplete="off">
  379. <span class="input-group-btn">
  380. <button class="btn btn-default" type="button" onclick="uploadMultiImage(this);">选择图片</button>
  381. <input type="hidden" value="{$name}" />
  382. </span>
  383. </div>
  384. <div class="input-group multi-img-details">
  385. EOF;
  386. if (is_array($value) && count($value) > 0) {
  387. foreach ($value as $row) {
  388. $s .= '
  389. <div class="multi-item">
  390. <img src="' . tomedia($row) . '" onerror="this.src=\'./resource/images/nopic.jpg\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail">
  391. <input type="hidden" name="' . $name . '[]" value="' . $row . '" >
  392. <em class="close" title="删除这张图片" onclick="deleteMultiImage(this)">×</em>
  393. </div>';
  394. }
  395. }
  396. $s .= '</div>';
  397. return $s;
  398. }
  399. function tpl_form_field_audio($name, $value = '', $options = array()) {
  400. if (!is_array($options)) {
  401. $options = array();
  402. }
  403. $options['direct'] = true;
  404. $options['multiple'] = false;
  405. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  406. $s = '';
  407. if (!defined('TPL_INIT_AUDIO')) {
  408. $s = '
  409. <script type="text/javascript">
  410. function showAudioDialog(elm, base64options, options) {
  411. require(["util"], function(util){
  412. var btn = $(elm);
  413. var ipt = btn.parent().prev();
  414. var val = ipt.val();
  415. util.audio(val, function(url){
  416. if(url && url.attachment && url.url){
  417. btn.prev().show();
  418. ipt.val(url.attachment);
  419. ipt.attr("filename",url.filename);
  420. ipt.attr("url",url.url);
  421. setAudioPlayer();
  422. }
  423. if(url && url.media_id){
  424. ipt.val(url.media_id);
  425. }
  426. }, "" , ' . json_encode($options) . ');
  427. });
  428. }
  429. function setAudioPlayer(){
  430. require(["jquery.jplayer"], function(){
  431. $(function(){
  432. $(".audio-player").each(function(){
  433. $(this).prev().find("button").eq(0).click(function(){
  434. var src = $(this).parent().prev().val();
  435. if($(this).find("i").hasClass("fa-stop")) {
  436. $(this).parent().parent().next().jPlayer("stop");
  437. } else {
  438. if(src) {
  439. $(this).parent().parent().next().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  440. }
  441. }
  442. });
  443. });
  444. $(".audio-player").jPlayer({
  445. playing: function() {
  446. $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
  447. },
  448. pause: function (event) {
  449. $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
  450. },
  451. swfPath: "resource/components/jplayer",
  452. supplied: "mp3"
  453. });
  454. $(".audio-player-media").each(function(){
  455. $(this).next().find(".audio-player-play").css("display", $(this).val() == "" ? "none" : "");
  456. });
  457. });
  458. });
  459. }
  460. setAudioPlayer();
  461. </script>';
  462. echo $s;
  463. define('TPL_INIT_AUDIO', true);
  464. }
  465. $s .= '
  466. <div class="input-group">
  467. <input type="text" value="' . $value . '" name="' . $name . '" class="form-control audio-player-media" autocomplete="off" ' . ($options['extras']['text'] ? $options['extras']['text'] : '') . '>
  468. <span class="input-group-btn">
  469. <button class="btn btn-default audio-player-play" type="button" style="display:none;"><i class="fa fa-play"></i></button>
  470. <button class="btn btn-default" type="button" onclick="showAudioDialog(this, \'' . base64_encode(iserializer($options)) . '\',' . str_replace('"', '\'', json_encode($options)) . ');">选择媒体文件</button>
  471. </span>
  472. </div>
  473. <div class="input-group audio-player"></div>';
  474. return $s;
  475. }
  476. function tpl_form_field_multi_audio($name, $value = array(), $options = array()) {
  477. $s = '';
  478. $options['direct'] = false;
  479. $options['multiple'] = true;
  480. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  481. if (!defined('TPL_INIT_MULTI_AUDIO')) {
  482. $s .= '
  483. <script type="text/javascript">
  484. function showMultiAudioDialog(elm, name) {
  485. require(["util"], function(util){
  486. var btn = $(elm);
  487. var ipt = btn.parent().prev();
  488. var val = ipt.val();
  489. util.audio(val, function(urls){
  490. $.each(urls, function(idx, url){
  491. 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>\');
  492. $(elm).parent().parent().next().append(obj);
  493. setMultiAudioPlayer(obj);
  494. });
  495. }, ' . json_encode($options) . ');
  496. });
  497. }
  498. function deleteMultiAudio(elm){
  499. $(elm).parent().parent().parent().remove();
  500. }
  501. function setMultiAudioPlayer(elm){
  502. require(["jquery.jplayer"], function(){
  503. $(".multi-audio-player",$(elm)).next().find("button").eq(0).click(function(){
  504. var src = $(this).parent().prev().val();
  505. if($(this).find("i").hasClass("fa-stop")) {
  506. $(this).parent().parent().prev().jPlayer("stop");
  507. } else {
  508. if(src) {
  509. $(this).parent().parent().prev().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  510. }
  511. }
  512. });
  513. $(".multi-audio-player",$(elm)).jPlayer({
  514. playing: function() {
  515. $(this).next().find("i").eq(0).removeClass("fa-play").addClass("fa-stop");
  516. },
  517. pause: function (event) {
  518. $(this).next().find("i").eq(0).removeClass("fa-stop").addClass("fa-play");
  519. },
  520. swfPath: "resource/components/jplayer",
  521. supplied: "mp3"
  522. });
  523. });
  524. }
  525. </script>';
  526. define('TPL_INIT_MULTI_AUDIO', true);
  527. }
  528. $s .= '
  529. <div class="input-group">
  530. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传音乐" autocomplete="off">
  531. <span class="input-group-btn">
  532. <button class="btn btn-default" type="button" onclick="showMultiAudioDialog(this,\'' . $name . '\');">选择音乐</button>
  533. </span>
  534. </div>
  535. <div class="input-group multi-audio-details clear-fix" style="margin-top:.5em;">';
  536. if (!empty($value) && !is_array($value)) {
  537. $value = array($value);
  538. }
  539. if (is_array($value) && count($value) > 0) {
  540. $n = 0;
  541. foreach ($value as $row) {
  542. $m = random(8);
  543. $s .= '
  544. <div class="multi-audio-item multi-audio-item-' . $n . '-' . $m . '" style="height: 40px; position:relative; float: left; margin-right: 18px;">
  545. <div class="multi-audio-player"></div>
  546. <div class="input-group">
  547. <input type="text" class="form-control" value="' . $row . '" readonly/>
  548. <div class="input-group-btn">
  549. <button class="btn btn-default" type="button"><i class="fa fa-play"></i></button>
  550. <button class="btn btn-default" onclick="deleteMultiAudio(this)" type="button"><i class="fa fa-remove"></i></button>
  551. </div>
  552. </div>
  553. <input type="hidden" name="' . $name . '[]" value="' . $row . '">
  554. </div>
  555. <script language="javascript">setMultiAudioPlayer($(".multi-audio-item-' . $n . '-' . $m . '"));</script>';
  556. $n++;
  557. }
  558. }
  559. $s .= '
  560. </div>';
  561. return $s;
  562. }
  563. function tpl_form_field_video($name, $value = '', $options = array()) {
  564. if(!is_array($options)){
  565. $options = array();
  566. }
  567. if (!is_array($options)) {
  568. $options = array();
  569. }
  570. $options['direct'] = true;
  571. $options['multi'] = false;
  572. $options['type'] = 'video';
  573. $options['fileSizeLimit'] = intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024;
  574. $s = '';
  575. if (!defined('TPL_INIT_VIDEO')) {
  576. $s = '
  577. <script type="text/javascript">
  578. function showVideoDialog(elm, options) {
  579. require(["util"], function(util){
  580. var btn = $(elm);
  581. var ipt = btn.parent().prev();
  582. var val = ipt.val();
  583. util.audio(val, function(url){
  584. if(url && url.attachment && url.url){
  585. btn.prev().show();
  586. ipt.val(url.attachment);
  587. ipt.attr("filename",url.filename);
  588. ipt.attr("url",url.url);
  589. }
  590. if(url && url.media_id){
  591. ipt.val(url.media_id);
  592. }
  593. }, '.json_encode($options).');
  594. });
  595. }
  596. </script>';
  597. echo $s;
  598. define('TPL_INIT_VIDEO', true);
  599. }
  600. $s .= '
  601. <div class="input-group">
  602. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  603. <span class="input-group-btn">
  604. <button class="btn btn-default" type="button" onclick="showVideoDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  605. </span>
  606. </div>';
  607. return $s;
  608. }
  609. function tpl_form_field_wechat_image($name, $value = '', $default = '', $options = array()) {
  610. global $_W;
  611. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  612. $options['account_error'] = 1;
  613. } else {
  614. $options['acid'] = $_W['acid'];
  615. }
  616. if(empty($default)) {
  617. $default = './resource/images/nopic.jpg';
  618. }
  619. $val = $default;
  620. if (!empty($value)) {
  621. $media_data = (array)media2local($value, true);
  622. $val = $media_data['attachment'];
  623. }
  624. if (empty($options['class_extra'])) {
  625. $options['class_extra'] = '';
  626. }
  627. $options['direct'] = true;
  628. $options['multiple'] = false;
  629. $options['type'] = empty($options['type']) ? 'image' : $options['type'];
  630. $s = '';
  631. if (!defined('TPL_INIT_WECHAT_IMAGE')) {
  632. $s = '
  633. <script type="text/javascript">
  634. function showWechatImageDialog(elm, options) {
  635. require(["util"], function(util){
  636. var btn = $(elm);
  637. var ipt = btn.parent().prev();
  638. var val = ipt.val();
  639. var img = ipt.parent().next().children();
  640. util.wechat_image(val, function(url){
  641. if(url.media_id){
  642. if(img.length > 0){
  643. img.get(0).src = url.url;
  644. }
  645. ipt.val(url.media_id);
  646. }
  647. }, options);
  648. });
  649. }
  650. function deleteImage(elm){
  651. $(elm).prev().attr("src", "./resource/images/nopic.jpg");
  652. $(elm).parent().prev().find("input").val("");
  653. }
  654. </script>';
  655. define('TPL_INIT_WECHAT_IMAGE', true);
  656. }
  657. $s .= '
  658. <div class="input-group ' . $options['class_extra'] . '">
  659. <input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
  660. <span class="input-group-btn">
  661. <button class="btn btn-default" type="button" onclick="showWechatImageDialog(this, ' . str_replace('"', '\'', json_encode($options)) . ');">选择图片</button>
  662. </span>
  663. </div>';
  664. $s .=
  665. '<div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
  666. <img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
  667. <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
  668. </div>';
  669. if (!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)) {
  670. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  671. }
  672. return $s;
  673. }
  674. function tpl_form_field_wechat_multi_image($name, $value = '', $default = '', $options = array()) {
  675. global $_W;
  676. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  677. $options['account_error'] = 1;
  678. } else {
  679. $options['acid'] = $_W['acid'];
  680. }
  681. if(empty($default)) {
  682. $default = './resource/images/nopic.jpg';
  683. }
  684. if(empty($options['class_extra'])) {
  685. $options['class_extra'] = '';
  686. }
  687. $options['direct'] = false;
  688. $options['multiple'] = true;
  689. $options['type'] = empty($options['type']) ? 'image' : $options['type'];
  690. $s = '';
  691. if (!defined('TPL_INIT_WECHAT_MULTI_IMAGE')) {
  692. $s = '
  693. <script type="text/javascript">
  694. function uploadWechatMultiImage(elm) {
  695. var name = $(elm).next().val();
  696. util.wechat_image("", function(urls){
  697. $.each(urls, function(idx, url){
  698. $(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>\');
  699. });
  700. }, '.json_encode($options).');
  701. }
  702. function deleteWechatMultiImage(elm){
  703. $(elm).parent().remove();
  704. }
  705. </script>';
  706. define('TPL_INIT_WECHAT_MULTI_IMAGE', true);
  707. }
  708. $s .= <<<EOF
  709. <div class="input-group">
  710. <input type="text" class="form-control" readonly="readonly" value="" placeholder="批量上传图片" autocomplete="off">
  711. <span class="input-group-btn">
  712. <button class="btn btn-default" type="button" onclick="uploadWechatMultiImage(this);">选择图片</button>
  713. <input type="hidden" value="{$name}" />
  714. </span>
  715. </div>
  716. <div class="input-group multi-img-details">
  717. EOF;
  718. if (is_array($value) && count($value)>0) {
  719. foreach ($value as $row) {
  720. $s .='
  721. <div class="multi-item">
  722. <img src="'.media2local($row).'" onerror="this.src=\'./resource/images/nopic.jpg\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail">
  723. <input type="hidden" name="'.$name.'[]" value="'.$row.'" >
  724. <em class="close" title="删除这张图片" onclick="deleteWechatMultiImage(this)">×</em>
  725. </div>';
  726. }
  727. }
  728. $s .= '</div>';
  729. return $s;
  730. }
  731. function tpl_form_field_wechat_voice($name, $value = '', $options = array()) {
  732. global $_W;
  733. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  734. $options['account_error'] = 1;
  735. } else {
  736. $options['acid'] = $_W['acid'];
  737. }
  738. if(!empty($value)) {
  739. $media_data = (array)media2local($value, true);
  740. $val = $media_data['attachment'];
  741. }
  742. if(!is_array($options)){
  743. $options = array();
  744. }
  745. $options['direct'] = true;
  746. $options['multiple'] = false;
  747. $options['type'] = 'voice';
  748. $s = '';
  749. if (!defined('TPL_INIT_WECHAT_VOICE')) {
  750. $s = '
  751. <script type="text/javascript">
  752. function showWechatVoiceDialog(elm, options) {
  753. require(["util"], function(util){
  754. var btn = $(elm);
  755. var ipt = btn.parent().prev();
  756. var val = ipt.val();
  757. util.wechat_audio(val, function(url){
  758. if(url && url.media_id && url.url){
  759. btn.prev().show();
  760. ipt.val(url.media_id);
  761. ipt.attr("media_id",url.media_id);
  762. ipt.attr("url",url.url);
  763. setWechatAudioPlayer();
  764. }
  765. if(url && url.media_id){
  766. ipt.val(url.media_id);
  767. }
  768. } , '.json_encode($options).');
  769. });
  770. }
  771. function setWechatAudioPlayer(){
  772. require(["jquery.jplayer"], function(){
  773. $(function(){
  774. $(".audio-player").each(function(){
  775. $(this).prev().find("button").eq(0).click(function(){
  776. var src = $(this).parent().prev().attr("url");
  777. if($(this).find("i").hasClass("fa-stop")) {
  778. $(this).parent().parent().next().jPlayer("stop");
  779. } else {
  780. if(src) {
  781. $(this).parent().parent().next().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  782. }
  783. }
  784. });
  785. });
  786. $(".audio-player").jPlayer({
  787. playing: function() {
  788. $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
  789. },
  790. pause: function (event) {
  791. $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
  792. },
  793. swfPath: "resource/components/jplayer",
  794. supplied: "mp3"
  795. });
  796. $(".audio-player-media").each(function(){
  797. $(this).next().find(".audio-player-play").css("display", $(this).val() == "" ? "none" : "");
  798. });
  799. });
  800. });
  801. }
  802. setWechatAudioPlayer();
  803. </script>';
  804. echo $s;
  805. define('TPL_INIT_WECHAT_VOICE', true);
  806. }
  807. $s .= '
  808. <div class="input-group">
  809. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control audio-player-media" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  810. <span class="input-group-btn">
  811. <button class="btn btn-default audio-player-play" type="button" style="display:none"><i class="fa fa-play"></i></button>
  812. <button class="btn btn-default" type="button" onclick="showWechatVoiceDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  813. </span>
  814. </div>
  815. <div class="input-group audio-player">
  816. </div>';
  817. if(!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)){
  818. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  819. }
  820. return $s;
  821. }
  822. function tpl_form_field_wechat_video($name, $value = '', $options = array()) {
  823. global $_W;
  824. if(!$_W['acid'] || $_W['account']['level'] < 3) {
  825. $options['account_error'] = 1;
  826. } else {
  827. $options['acid'] = $_W['acid'];
  828. }
  829. if(!empty($value)) {
  830. $media_data = (array)media2local($value, true);
  831. $val = $media_data['attachment'];
  832. }
  833. if(!is_array($options)){
  834. $options = array();
  835. }
  836. if(empty($options['tabs'])){
  837. $options['tabs'] = array('video'=>'active', 'browser'=>'');
  838. }
  839. $options = array_elements(array('tabs','global','dest_dir', 'acid', 'error'), $options);
  840. $options['direct'] = true;
  841. $options['multi'] = false;
  842. $options['type'] = 'video';
  843. $s = '';
  844. if (!defined('TPL_INIT_WECHAT_VIDEO')) {
  845. $s = '
  846. <script type="text/javascript">
  847. function showWechatVideoDialog(elm, options) {
  848. require(["util"], function(util){
  849. var btn = $(elm);
  850. var ipt = btn.parent().prev();
  851. var val = ipt.val();
  852. util.wechat_audio(val, function(url){
  853. if(url && url.media_id && url.url){
  854. btn.prev().show();
  855. ipt.val(url.media_id);
  856. ipt.attr("media_id",url.media_id);
  857. ipt.attr("url",url.url);
  858. }
  859. if(url && url.media_id){
  860. ipt.val(url.media_id);
  861. }
  862. }, '.json_encode($options).');
  863. });
  864. }
  865. </script>';
  866. echo $s;
  867. define('TPL_INIT_WECHAT_VIDEO', true);
  868. }
  869. $s .= '
  870. <div class="input-group">
  871. <input type="text" value="'.$value.'" name="'.$name.'" class="form-control" autocomplete="off" '.($options['extras']['text'] ? $options['extras']['text'] : '').'>
  872. <span class="input-group-btn">
  873. <button class="btn btn-default" type="button" onclick="showWechatVideoDialog(this,'.str_replace('"','\'', json_encode($options)).');">选择媒体文件</button>
  874. </span>
  875. </div>
  876. <div class="input-group audio-player">
  877. </div>';
  878. if(!empty($media_data) && $media_data['model'] == 'temp' && (time() - $media_data['createtime'] > 259200)){
  879. $s .= '<span class="help-block"><b class="text-danger">该素材已过期 [有效期为3天],请及时更新素材</b></span>';
  880. }
  881. return $s;
  882. }
  883. function tpl_form_field_location_category($name, $values = array(), $del = false) {
  884. $html = '';
  885. if (!defined('TPL_INIT_LOCATION_CATEGORY')) {
  886. $html .= '
  887. <script type="text/javascript">
  888. require(["location"], function(loc){
  889. $(".tpl-location-container").each(function(){
  890. var elms = {};
  891. elms.cate = $(this).find(".tpl-cate")[0];
  892. elms.sub = $(this).find(".tpl-sub")[0];
  893. elms.clas = $(this).find(".tpl-clas")[0];
  894. var vals = {};
  895. vals.cate = $(elms.cate).attr("data-value");
  896. vals.sub = $(elms.sub).attr("data-value");
  897. vals.clas = $(elms.clas).attr("data-value");
  898. loc.render(elms, vals, {withTitle: true});
  899. });
  900. });
  901. </script>';
  902. define('TPL_INIT_LOCATION_CATEGORY', true);
  903. }
  904. if (empty($values) || !is_array($values)) {
  905. $values = array('cate'=>'','sub'=>'','clas'=>'');
  906. }
  907. if(empty($values['cate'])) {
  908. $values['cate'] = '';
  909. }
  910. if(empty($values['sub'])) {
  911. $values['sub'] = '';
  912. }
  913. if(empty($values['clas'])) {
  914. $values['clas'] = '';
  915. }
  916. $html .= '
  917. <div class="row row-fix tpl-location-container">
  918. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  919. <select name="' . $name . '[cate]" data-value="' . $values['cate'] . '" class="form-control tpl-cate">
  920. </select>
  921. </div>
  922. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  923. <select name="' . $name . '[sub]" data-value="' . $values['sub'] . '" class="form-control tpl-sub">
  924. </select>
  925. </div>
  926. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
  927. <select name="' . $name . '[clas]" data-value="' . $values['clas'] . '" class="form-control tpl-clas">
  928. </select>
  929. </div>';
  930. if($del) {
  931. $html .='
  932. <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3" style="padding-top:5px">
  933. <a title="删除" onclick="$(this).parents(\'.tpl-location-container\').remove();return false;"><i class="fa fa-times-circle"></i></a>
  934. </div>
  935. </div>';
  936. } else {
  937. $html .= '</div>';
  938. }
  939. return $html;
  940. }
  941. function tpl_ueditor($id, $value = '', $options = array()) {
  942. $s = '';
  943. $options['height'] = empty($options['height']) ? 200 : $options['height'];
  944. $options['allow_upload_video'] = isset($options['allow_upload_video']) ? $options['allow_upload_video'] : true;
  945. $s .= !empty($id) ? "<textarea id=\"{$id}\" name=\"{$id}\" type=\"text/plain\" style=\"height:{$options['height']}px;\">{$value}</textarea>" : '';
  946. $s .= "
  947. <script type=\"text/javascript\">
  948. require(['util'], function(util){
  949. util.editor('" . ($id ? $id : "") . "', {
  950. height : {$options['height']},
  951. dest_dir : '" .($options['dest_dir'] ? $options['dest_dir'] : "") . "',
  952. image_limit : " . (intval($GLOBALS['_W']['setting']['upload']['image']['limit']) * 1024) . ",
  953. allow_upload_video : " . ($options['allow_upload_video'] ? 'true' : 'false') . ",
  954. audio_limit : " . (intval($GLOBALS['_W']['setting']['upload']['audio']['limit']) * 1024) . ",
  955. callback : ''
  956. });
  957. });
  958. </script>";
  959. return $s;
  960. }
  961. function tpl_edit_sms($name, $value, $uniacid, $url, $num) {
  962. $s = '
  963. <div class="input-group">
  964. <input type="text" name="'.$name.'" id="balance" readonly value="'.$value.'" class="form-control" autocomplete="off">
  965. <span class="input-group-btn">
  966. <button type="button" class="btn btn-default" data-toggle="modal" data-target="#edit_sms">编辑短信条数</button>
  967. </span>
  968. </div>
  969. <span class="help-block">请填写短信剩余条数,必须为整数。</span>
  970. <div class="modal fade" id="edit_sms" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  971. <div class="modal-dialog" role="document">
  972. <div class="modal-content">
  973. <div class="modal-header">
  974. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  975. <h4 class="modal-title" id="">修改短信条数</h4>
  976. </div>
  977. <div class="modal-body" style="height: 100px;">
  978. <div class="form-group">
  979. <label class="col-xs-12 col-sm-5 col-md-6 col-lg-3 control-label">短信条数</label>
  980. <div class="col-sm-6 col-xs-12 col-md-7">
  981. <div class="input-group" style="width: 180px;">
  982. <div class="input-group-btn">
  983. <button type="button" class="btn btn-defaultt label-success" id="edit_add">+</button>
  984. </div>
  985. <!--<span class="input-group-addon label-danger" id="edit_alert" style="width: 10px;">+ </span>-->
  986. <input type="text" class="form-control" id="edit_num" value="+">
  987. <div class="input-group-btn">
  988. <button type="button" class="btn btn-default" id="edit_minus">-</button>
  989. </div>
  990. </div>
  991. <div class="help-block">点击加号或减号切换修改短信条数方式<br>最多可添加<span id="count_sms">'.$num.'</span>条短信</div>
  992. </div>
  993. </div>
  994. </div>
  995. <div class="modal-footer">
  996. <button type="button" id="edit_sms_sub" class="btn btn-primary">保存</button>
  997. </div>
  998. </div>
  999. </div>
  1000. </div>
  1001. <script>
  1002. var status = \'add\';
  1003. $(\'#edit_add\').click(function() {
  1004. status = \'add\';
  1005. var sign = status == \'add\' ? \'+\' : \'-\';
  1006. var edit_num = $(\'#edit_num\').val();
  1007. if (edit_num == \'\') {
  1008. $(\'#edit_num\').val(sign)
  1009. return;
  1010. }
  1011. if (isNaN(edit_num.substr(1)) || edit_num.substr(1) == \'\') {
  1012. edit_num = \'\';
  1013. }
  1014. $(\'#edit_num\').val(\'+\'+Math.abs(edit_num));
  1015. if (edit_num == \'\') {
  1016. $(\'#edit_num\').val(sign);
  1017. }
  1018. $(\'#edit_add\').attr(\'class\', \'btn btn-defaultt label-success\');
  1019. $(\'#edit_minus\').attr(\'class\', \'btn btn-default\');
  1020. });
  1021. $(\'#edit_num\').keyup(function() {
  1022. var sign = status == \'add\' ? \'+\' : \'-\';
  1023. if ($(\'#edit_num\').val() == \'\') {
  1024. return ;
  1025. }
  1026. if (isNaN($(\'#edit_num\').val()) && $(\'#edit_num\').val() != sign) {
  1027. $(\'#edit_num\').val(\'\');
  1028. return;
  1029. }
  1030. if ($(\'#edit_num\').val().indexOf(sign) < 0) {
  1031. var val = parseInt(Math.abs($(\'#edit_num\').val()));
  1032. if (val == 0) {
  1033. $(\'#edit_num\').val(sign);
  1034. } else {
  1035. $(\'#edit_num\').val(sign + val);
  1036. }
  1037. }
  1038. });
  1039. $(\'#edit_minus\').click(function() {
  1040. status = \'minus\';
  1041. var sign = status == \'add\' ? \'+\' : \'-\';
  1042. var edit_num = $(\'#edit_num\').val();
  1043. if (edit_num == \'\') {
  1044. $(\'#edit_num\').val(sign)
  1045. return;
  1046. }
  1047. if (isNaN(edit_num.substr(1)) || edit_num.substr(1) == \'\') {
  1048. edit_num = \'\';
  1049. }
  1050. $(\'#edit_num\').val(\'-\'+Math.abs(edit_num));
  1051. if (edit_num == \'\') {
  1052. $(\'#edit_num\').val(sign);
  1053. }
  1054. $(\'#edit_minus\').attr(\'class\', \'btn btn-defaultt label-danger\');
  1055. $(\'#edit_add\').attr(\'class\', \'btn btn-default\');
  1056. });
  1057. $(\'#edit_sms_sub\').click(function () {
  1058. var edit_num = $(\'#edit_num\').val() == \'\' ? 0 : Math.abs(parseInt($(\'#edit_num\').val()));
  1059. var uniacid = '.$uniacid.';
  1060. $.post(\''.$url.'\', {\'balance\' : edit_num, \'uniacid\' : uniacid, \'status\' : status}, function(data) {
  1061. var data = $.parseJSON(data);
  1062. $(\'#count_sms\').html(data.message.message.count);
  1063. if (data.message.errno > 0) {
  1064. $(\'#balance\').val(data.message.message.num);
  1065. $(\'#edit_sms\').modal(\'toggle\');
  1066. } else {
  1067. util.message(\'您现有短信数量为0,请联系服务商购买短信\');
  1068. $(\'#edit_sms\').modal(\'toggle\');
  1069. }
  1070. $(\'#edit_num\').val(\'\');
  1071. $(\'#edit_add\').trigger(\'click\');
  1072. });
  1073. });
  1074. </script>
  1075. ';
  1076. return $s;
  1077. }
  1078. function tpl_coupon_colors($name, $value = 'Color082') {
  1079. load()->model('activity');
  1080. $options = activity_coupon_colors();
  1081. empty($name) && ($name = 'coupon_color');
  1082. if (!defined('TPL_INIT_COUPON_COLOR')) {
  1083. $html = '
  1084. <script type="text/javascript">
  1085. function showCouponColor(eml) {
  1086. var dropdown = $(eml).parent().parent().next();
  1087. dropdown.show();
  1088. $(document).click(function(){
  1089. dropdown.hide();
  1090. });
  1091. $(".coupon-color").click(function(e){
  1092. e.stopPropagation();
  1093. });
  1094. $(".dropdown-menu li").click(function(){
  1095. $(eml).parent().prev().css("background", $(this).attr("data-color"));
  1096. $(eml).parent().prev().css("border-color", $(this).attr("data-color"));
  1097. $(eml).parent().prev().prev().prev().val($(this).attr("data-name"));
  1098. $(eml).parent().prev().prev().val($(this).attr("data-color"));
  1099. dropdown.hide();
  1100. $(document).unbind("click");
  1101. $(".dropdown-menu li, .coupon-color").unbind("click");
  1102. });
  1103. }
  1104. </script>';
  1105. define('TPL_INIT_COUPON_COLOR', true);
  1106. }
  1107. $html .= '
  1108. <div class="col-sm-9 col-xs-12 coupon-color" style="position: relative;width:200px;">
  1109. <div class="input-group" style="width:200px;">
  1110. <input type="text" class="form-control" name="'.$name.'" value="'.$value.'"/>
  1111. <input type="hidden" name="'.$name.'-value" class="form-control" value="'.$value.'"/>
  1112. <span class="input-group-addon" style="width:35px;background:'.$options[$value].'"></span>
  1113. <span class="input-group-btn">
  1114. <button class="btn btn-default" type="button" onclick="showCouponColor(this);">选择颜色</button>
  1115. </span>
  1116. </div>
  1117. <div class="dropdown-menu" style="display:none;padding:6px 0 0 6px;width:185px;position: absolute;top:35px;left:15px">
  1118. <ul style="padding:0">
  1119. ';
  1120. if(!empty($options)) {
  1121. foreach($options as $colorname => $colorvalue) {
  1122. $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>';
  1123. }
  1124. }
  1125. $html .= '
  1126. </ul>
  1127. </div>
  1128. </div>
  1129. ';
  1130. return $html;
  1131. }