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

/th/application/views/admin/article.php

https://gitlab.com/anurat/earththailand
PHP | 321 lines | 283 code | 38 blank | 0 comment | 7 complexity | c439eb1ea4e49cc6ed894f57380ca8c0 MD5 | raw file
  1. <?php
  2. if( empty( $article_id ) ) {
  3. ?>
  4. <h1><?php echo $this->lang->line('menu_topmenu'); ?> > <?php echo $this->lang->line('menu_articles'); ?>
  5. > <?php echo $this->lang->line('menu_add_article'); ?></h1>
  6. <?php
  7. }
  8. else {
  9. ?>
  10. <h1><?php echo $this->lang->line('menu_topmenu'); ?> > <?php echo $this->lang->line('menu_articles'); ?>
  11. > <?php echo $this->lang->line('menu_update_article'); ?></h1>
  12. <?php
  13. }
  14. $cms_article = $this->cms_model->get_cms_article();
  15. $current_id = ( empty( $article_id ) )? $cms_article->get_next_id(): $article->get_article_id();
  16. $title = ( empty( $article_id ) )? '': htmlspecialchars( $article->get_title() );
  17. $video_code = ( empty( $article_id ) )? '': $article->get_video_code();
  18. $description = ( empty( $article_id ) )? '': $article->get_description();
  19. $attachment = ( empty( $article_id ) )? '': $article->get_attachment();
  20. $list_title = ( empty( $article_id ) )? '': htmlspecialchars( $article->get_list_title() );
  21. $list_desc = ( empty( $article_id ) )? '': $article->get_list_desc();
  22. $list_img = ( empty( $article_id ) )? '': $article->get_list_img();
  23. $article_date = ( empty( $article_id ) )? time(): $article->get_article_date();
  24. ?>
  25. <link rel="stylesheet" href="<?php echo site_url( 'js/jquery-ui-1.11.0.custom/jquery-ui.min.css' ); ?>" type="text/css" />
  26. <script src="<?php echo site_url( 'js/jquery-ui-1.11.0.custom/jquery-ui.min.js' ); ?>" ></script>
  27. <script type="text/javascript" >
  28. $( function() {
  29. CKFinder.setupCKEditor( null, '/th/ckfinder/' );
  30. var editor1 = CKEDITOR.replace( 'editor1', {
  31. bodyClass: 'item_description',
  32. height: 100
  33. });
  34. var editor2 = CKEDITOR.replace( 'editor2', {
  35. bodyClass: 'article_description',
  36. height: 1000
  37. });
  38. var editor3 = CKEDITOR.replace( 'editor3', {
  39. bodyClass: 'article_description',
  40. height: 100
  41. });
  42. load_images( 'article', <?php echo $current_id; ?>, '<?php echo site_url(); ?>' );
  43. $('a#upload_button').on( 'click', function(e) {
  44. e.preventDefault();
  45. CKFinder.popup({
  46. basePath: '/th/ckfinder/',
  47. selectActionFunction: function( file_url ) {
  48. load_images( 'article', <?php echo $current_id; ?>, '<?php echo site_url(); ?>' );
  49. },
  50. startupPath : "Articles:/<?php echo $current_id; ?>/"
  51. });
  52. });
  53. $( "#sortable_box" ).sortable({
  54. placeholder: "ui-state-highlight",
  55. containment: "div#content",
  56. delay: "150",
  57. scroll: true,
  58. scrollSensitivity: 100,
  59. update: function( event, ui ) {
  60. var a_image = new Array();
  61. var a_order = new Array();
  62. $("#sortable_box li").each( function(i) {
  63. a_image.push( $(this).data('image-id') );
  64. a_order.push( $(this).data('order') );
  65. });
  66. $.ajax({
  67. data: { image: a_image, order: a_order },
  68. type: 'POST',
  69. url: "<?php echo site_url( "ajax/sortable/image" ); ?>"
  70. })
  71. .always( function() {
  72. $('#message').html( 'Reordering complete.' )
  73. .show()
  74. .delay( 5000 )
  75. .fadeOut();
  76. });
  77. }
  78. });
  79. var dialog = $( "#dialog_form" ).dialog({
  80. autoOpen: false,
  81. height: 250,
  82. width: 350,
  83. modal: true,
  84. buttons: {
  85. Update: function() {
  86. $.ajax({
  87. data: {
  88. image_id: $("#image_id").val(),
  89. name: $("#name").val(),
  90. description: $("#description").val()
  91. },
  92. type: 'POST',
  93. url: "<?php echo site_url( "ajax/image/update" ); ?>"
  94. })
  95. .always( function( data ) {
  96. load_images( 'article', <?php echo $current_id; ?>, '<?php echo site_url(); ?>' );
  97. $('#message').html( 'Image info updated.' )
  98. .show()
  99. .delay( 5000 )
  100. .fadeOut();
  101. });
  102. dialog.dialog( "close" );
  103. },
  104. Cancel: function() {
  105. dialog.dialog( "close" );
  106. }
  107. },
  108. });
  109. $('#sortable_box').on( 'click', 'span.box', function() {
  110. var $li = $(this).parent();
  111. $("#image_id").val( $li.data("image-id") );
  112. $("#name").val( $li.find("span.name").html() );
  113. $("#description").val( $li.find("span.description").html() );
  114. dialog.dialog( "open" );
  115. });
  116. $('#list_img_button').on( 'click', function(e) {
  117. e.preventDefault();
  118. CKFinder.popup({
  119. basePath: '/th/ckfinder/',
  120. selectActionFunction: function( file_url ) {
  121. d = new Date();
  122. $("#article_list_img").attr("src", file_url +"?"+d.getTime());
  123. var n = file_url.indexOf( 'userfiles/' ) +10;
  124. $("#list_img").val( file_url.substring( n ) );
  125. },
  126. startupPath : "Articles:/item/"
  127. });
  128. });
  129. $('a#clear_list_image').on( 'click', function( e ) {
  130. e.preventDefault();
  131. $("#article_list_img").attr("src", "" );
  132. $("#list_img").val("");
  133. });
  134. $("#article_date").datepicker({
  135. dateFormat: "d MM yy",
  136. changeMonth: true,
  137. changeYear: true,
  138. yearRange: "2005:2020"
  139. });
  140. $("#checkbox_box").buttonset();
  141. $('div.save_cancel a.button').on( 'click', function(e) {
  142. e.preventDefault();
  143. var button_type = $(this).data('button-type');
  144. switch( button_type ) {
  145. case 'cancel':
  146. history.back();
  147. break;
  148. default:
  149. $('form[name=article_form] input[name=save_type]').val( button_type );
  150. $('form[name=article_form]').submit();
  151. break;
  152. }
  153. });
  154. });
  155. function load_images( type, id, base_url ) {
  156. $.getJSON( base_url +'ajax/gallery_image/' +type +'/' +id, function( images ) {
  157. var html = '';
  158. $.each( images, function( i, image ) {
  159. html += "<li class=\"ui-state-default\" data-image-id=\"" +image._image_id +"\" data-order=\"" +image._order +"\" title=\"" +image._path +"\" >\n"
  160. +" <span class=\"ui-icon ui-icon-arrow-4\"></span>\n"
  161. +" <div>\n"
  162. +" <img src=\"" +base_url +"userfiles/_thumbs/Articles/" +id +"/" +image._path +"\" alt=\"\" />\n"
  163. +" </div>\n"
  164. +" <span class=\"box name\" title=\"" +image._name +"\" >" +image._name +"</span>\n"
  165. +" <span class=\"box description\" title=\"" +image._description +"\" >" +image._description +"</span>\n"
  166. +"</li>\n";
  167. });
  168. $("#sortable_box").html( html );
  169. $("#image_no").html( images.length );
  170. });
  171. }
  172. </script>
  173. <form method="post" name="article_form">
  174. <div class="save_cancel" >
  175. <input type="hidden" name="previous_url" value="<?php echo $previous_url; ?>" />
  176. <a href="#" class="button" data-button-type="save_close" ><?php echo $this->lang->line('header_save_close'); ?></a>
  177. <a href="#" class="button" data-button-type="save_new" ><?php echo $this->lang->line('header_save_new'); ?></a>
  178. <?php
  179. if( !empty( $article_id ) ) {
  180. ?>
  181. <a href="#" class="button" data-button-type="save" ><?php echo $this->lang->line('header_save'); ?></a>
  182. <?php
  183. }
  184. ?>
  185. <a href="#" class="button" data-button-type="cancel" ><?php echo $this->lang->line('header_cancel'); ?></a>
  186. </div>
  187. <?php echo $this->lang->line('article_title'); ?><br />
  188. <input type="text" class="title" name="title" value="<?php echo $title; ?>" />
  189. <br />
  190. <br />
  191. <?php echo $this->lang->line('article_video_code'); ?><br />
  192. <textarea name="video_code" ><?php echo $video_code; ?></textarea>
  193. <br />
  194. <br />
  195. <?php echo $this->lang->line('article_image'); ?><br />
  196. <a href="#" class="button" id="upload_button" ><?php echo $this->lang->line( 'header_upload' ); ?></a>
  197. <span id="message" class="result" ></span><br />
  198. <?php echo $this->lang->line('article_image_folder'); ?> <b>Articles/<?php echo $current_id; ?></b> <br />
  199. <?php echo $this->lang->line('article_image_no'); ?>: <span id="image_no" ></span>
  200. <ul id="sortable_box" ></ul>
  201. <br />
  202. <?php echo $this->lang->line('article_description'); ?><br />
  203. <textarea class="ckeditor" name="editor2" >
  204. <?php echo $description; ?>
  205. </textarea>
  206. <br />
  207. <?php echo $this->lang->line('article_attachment'); ?><br />
  208. <textarea class="ckeditor" name="editor3" >
  209. <?php echo $attachment; ?>
  210. </textarea>
  211. <br />
  212. <?php echo $this->lang->line('article_tags'); ?><br />
  213. <input type="text" name="tags" value="<?php echo $tags; ?>" /><br />
  214. <br />
  215. <hr />
  216. <h2 id="list_item" ><?php echo $this->lang->line('header_item'); ?></h2>
  217. <?php echo $this->lang->line('article_list_title'); ?><br />
  218. <input type="text" class="title" name="list_title" value="<?php echo $list_title; ?>" /><br />
  219. <?php echo $this->lang->line('article_newline'); ?><br />
  220. <br />
  221. <?php echo $this->lang->line('article_list_desc'); ?><br />
  222. <textarea class="ckeditor" name="editor1" >
  223. <?php echo $list_desc; ?>
  224. </textarea>
  225. <br />
  226. <?php echo $this->lang->line('article_list_img'); ?><br />
  227. <input type="text" id="list_img" name="list_img" style="width: 400px; " readonly="readonly"
  228. value="<?php echo $list_img; ?>" />
  229. <a href="#" class="button" id="list_img_button" ><?php echo $this->lang->line( 'header_upload' ); ?></a>
  230. <a href="#" id="clear_list_image" ><?php echo $this->lang->line('header_clear'); ?></a><br />
  231. <?php echo $this->lang->line('article_image_upload'); ?><br />
  232. <img id="article_list_img" src="<?php echo site_url( 'userfiles/' .$list_img ); ?>" style="max-width: 200px; max-height: 200px; " alt="" />
  233. <br />
  234. <br />
  235. <?php echo $this->lang->line('article_date'); ?><br />
  236. <input type="text" id="article_date" name="article_date" style="width: 400px; "
  237. value="<?php echo date( 'j F Y', $article_date ); ?>" /><br />
  238. <br />
  239. <?php echo $this->lang->line('header_category'); ?><br />
  240. <div id="checkbox_box">
  241. <?php
  242. $cms_category = $this->cms_model->get_cms_category();
  243. foreach( $category_list as $category ) {
  244. $category_id = $category->get_category_id();
  245. $has_cat_link = $cms_category->has_cat_link( $category_id, $cat_links );
  246. ?>
  247. <input type="checkbox" id="category[<?php echo $category_id; ?>]" name="category[<?php echo $category_id; ?>]"
  248. <?php echo ( empty( $article_id ) && $category_id == Cms_category::ARTICLE_CAT )? "checked=\"checked\"": ""; ?>
  249. <?php echo ( !empty( $article_id ) && $has_cat_link )? "checked=\"checked\"": ""; ?>
  250. ><label for="category[<?php echo $category_id; ?>]"><?php echo $category->get_title(); ?></label>
  251. <?php
  252. }
  253. ?>
  254. </div>
  255. <div class="save_cancel" >
  256. <a href="#" class="button" data-button-type="save_close" ><?php echo $this->lang->line('header_save_close'); ?></a>
  257. <a href="#" class="button" data-button-type="save_new" ><?php echo $this->lang->line('header_save_new'); ?></a>
  258. <?php
  259. if( !empty( $article_id ) ) {
  260. ?>
  261. <a href="#" class="button" data-button-type="save" ><?php echo $this->lang->line('header_save'); ?></a>
  262. <?php
  263. }
  264. ?>
  265. <a href="#" class="button" data-button-type="cancel" ><?php echo $this->lang->line('header_cancel'); ?></a>
  266. </div>
  267. <input type="hidden" name="save_type" value=""/>
  268. </form>
  269. <br />
  270. <div id="dialog_form" title="Update photo info" >
  271. <form>
  272. <fieldset>
  273. <label for="name">Name</label><br />
  274. <input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all"><br />
  275. <br />
  276. <label for="description">Description</label><br />
  277. <textarea name="description" id="description" class="textarea ui-widget-content ui-corner-all"></textarea><br />
  278. <!-- Allow form submission with keyboard without duplicating the dialog button -->
  279. <input type="hidden" name="image_id" id="image_id" value="" />
  280. <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
  281. </fieldset>
  282. </form>
  283. </div>