PageRenderTime 88ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/admin/admin_init.php

https://github.com/EmranAhmed/wp-easycart
PHP | 797 lines | 651 code | 85 blank | 61 comment | 100 complexity | 273d9a25e6aeb0bff2775f940ffb2bd5 MD5 | raw file
  1. <?php
  2. ////////////////////////////////////////////
  3. // ADMIN INITIALIZE/LOCALIZE AJAX Functions
  4. ////////////////////////////////////////////
  5. add_action( 'admin_enqueue_scripts', 'ec_load_admin_scripts' );
  6. add_action( 'admin_init', 'ec_register_settings' );
  7. add_action( 'admin_menu', 'ec_create_menu' );
  8. add_action( 'admin_init', 'ec_custom_downloads', 1 );
  9. add_action( 'admin_notices', 'ec_install_admin_notice' );
  10. add_action( 'save_post', 'ec_post_save_permalink_structure' );
  11. add_action( 'save_post', 'ec_post_save_match_store_meta', 13 );
  12. add_action( 'init', 'ec_add_editor_buttons' );
  13. add_action( 'admin_footer', 'ec_print_editor' );
  14. add_action( 'wp_ajax_ec_editor_update_sub_menu', 'ec_editor_update_sub_menu' );
  15. add_action( 'wp_ajax_ec_editor_update_subsub_menu', 'ec_editor_update_subsub_menu' );
  16. function ec_install_admin_notice() {
  17. if( isset( $_GET['page'] ) && isset( $_GET['ec_page'] ) && isset( $_GET['ec_panel'] ) && $_GET['page'] == "ec_adminv2" && $_GET['ec_page'] == "store-setup" && $_GET['ec_panel'] == "basic-setup" ){
  18. update_option( 'ec_option_show_install_message', '1' );
  19. }
  20. if( !get_option( 'ec_option_show_install_message' ) && ( !get_option( 'ec_option_accountpage' ) || !get_option( 'ec_option_cartpage' ) || !get_option( 'ec_option_storepage' ) ) ){
  21. ?>
  22. <div class="updated">
  23. <p>You Have not Setup Your WP EasyCart! Please <a href="admin.php?page=ec_adminv2&ec_page=store-setup&ec_panel=basic-setup">Click Here to Setup</a>.</p>
  24. </div>
  25. <?php
  26. }
  27. $ec_selected_theme = wp_get_theme();
  28. if( $ec_selected_theme->Name == "Twenty Fourteen" && substr( get_option( 'ec_option_base_theme' ), 0, 15 ) != "twenty-fourteen" ){
  29. ?>
  30. <div class="updated">
  31. <p>EasyCart notices that you are using the Twenty Fourteen WordPress theme, but not the Twenty Fourteen store design. Make the change to the cart for best results by <a href="admin.php?page=ec_adminv2&ec_page=store-setup&ec_panel=design-management">clicking here</a>.</p>
  32. </div>
  33. <?php
  34. }// Close check for latest WordPress theme
  35. // Check if the admin manage notice should be removed
  36. if( isset( $_GET['page'] ) && $_GET['page'] == "ec_adminv2" && isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "admin-console" && isset( $_GET['ec_panel'] ) && $_GET['ec_panel'] == "admin" && isset( $_GET['ec_notice'] ) && $_GET['ec_notice'] == "dismiss" ){
  37. update_option( 'ec_option_hide_admin_notice', '1' );
  38. }
  39. // Check if admin is installed
  40. if( !is_plugin_active( "wp-easycart-admin/wpeasycart-admin.php" ) ){
  41. ?>
  42. <div class="updated">
  43. <p>EasyCart is best run with the WP EasyCart Admin Console, <a href="admin.php?page=ec_adminv2&ec_page=admin-console&ec_panel=admin">click here to learn how it can be installed</a>.</p>
  44. </div>
  45. <?php
  46. }else if( !get_option( 'ec_option_hide_admin_notice' ) ){
  47. ?>
  48. <div class="updated">
  49. <p>Want to add/edit products, manage orders, manage users, or manage store rates? <a href="admin.php?page=ec_adminv2&ec_page=admin-console&ec_panel=admin">click here to view the WP EasyCart Admin Console</a>. <a href="admin.php?page=ec_adminv2&ec_page=admin-console&ec_panel=admin&ec_notice=dismiss">To dismiss this notice, click here</a></p>
  50. </div>
  51. <?php
  52. }
  53. if( !file_exists( WP_PLUGIN_DIR . "/wp-easycart-data/" ) ){ ?>
  54. <div class="error">
  55. <p>Your server appears to be missing the wp-easycart-data folder, which could cause data loss on upgrade. Please <a href="http://www.wpeasycart.com/plugin-update-help" target="_blank">click here</a> to learn how to correct this issue.</p>
  56. </div>
  57. <?php
  58. }
  59. if( get_option( 'ec_option_display_as_catalog' ) ){ ?>
  60. <div class="updated">
  61. <p>You currently have your store in catalog only mode. This means that your customers can only view the products, not add to cart or checkout. If you think this was turned on by mistake, you can turn it off by <a href="admin.php?page=ec_adminv2&ec_page=store-setup&ec_panel=advanced-setup">clicking here</a> and set Display Store as Catalog to Off.</p>
  62. </div>
  63. <?php }
  64. }
  65. function ec_load_admin_scripts( ){
  66. include( 'style.php' );
  67. wp_enqueue_script('thickbox');
  68. wp_enqueue_style('thickbox');
  69. wp_enqueue_script('media-upload');
  70. wp_register_script( 'wpeasycart_admin_js', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/admin/admin_ajax_functions.js' ), array( 'jquery' ) );
  71. wp_enqueue_script( 'wpeasycart_admin_js' );
  72. wp_register_script( 'wpeasycart_simple_admin_js', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/admin/assets/js/admin.js' ), array( 'jquery' ) );
  73. wp_enqueue_script( 'wpeasycart_simple_admin_js' );
  74. $https_link = "";
  75. if( class_exists( "WordPressHTTPS" ) ){
  76. $https_class = new WordPressHTTPS( );
  77. $https_link = $https_class->getHttpsUrl() . '/wp-admin/admin-ajax.php';
  78. }else{
  79. $https_link = str_replace( "http://", "https://", admin_url( 'admin-ajax.php' ) );
  80. }
  81. if( isset( $_SERVER['HTTPS'] ) )
  82. wp_localize_script( 'wpeasycart_admin_js', 'ajax_object', array( 'ajax_url' => $https_link ) );
  83. else
  84. wp_localize_script( 'wpeasycart_admin_js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
  85. }
  86. function ec_register_settings() {
  87. //register admin css
  88. wp_register_style( 'wpeasycart_admin_css', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/admin/wpadmin_stylesheet.css' ), array(), '2.1.2' );
  89. wp_enqueue_style( 'wpeasycart_admin_css' );
  90. //register admin css
  91. wp_register_style( 'wpeasycart_adminv2_css', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/admin/assets/css/wpeasycart_adminv2.css' ), array(), '2.1.2' );
  92. wp_enqueue_style( 'wpeasycart_adminv2_css' );
  93. //register admin css
  94. wp_register_style( 'wpeasycart_editor_css', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/admin/assets/css/editor.css' ), array(), '2.1.2' );
  95. wp_enqueue_style( 'wpeasycart_editor_css' );
  96. //register options
  97. $wpoptions = new ec_wpoptionset();
  98. $wpoptions->register_options();
  99. }
  100. function ec_create_menu() {
  101. //V2 Admin
  102. $wp_version = get_bloginfo( 'version' );
  103. if( $wp_version < 3.8 ){
  104. add_menu_page( 'EasyCart Admin', 'EasyCart Admin', 'manage_options', 'ec_adminv2', 'ec_adminv2_page_callback', plugins_url( 'images/wp_16x16_icon.png', __FILE__ ) );
  105. }else{
  106. add_menu_page( 'EasyCart Admin', 'EasyCart Admin', 'manage_options', 'ec_adminv2', 'ec_adminv2_page_callback', 'dashicons-cart' );
  107. //add_menu_page( 'EasyCart Admin', 'EasyCart Admin', 'manage_options', 'ec_adminv2', 'ec_adminv2_page_callback', plugins_url( 'assets/images/sidebar_icon.png', __FILE__ ) );
  108. }
  109. }
  110. function ec_custom_downloads( ){
  111. if( is_admin( ) && isset( $_GET['page'] ) && isset( $_GET['ec_page'] ) && isset( $_GET['ec_panel'] ) && isset( $_GET['ec_action'] ) && $_GET['page'] == "ec_adminv2" && $_GET['ec_page'] == "dashboard" && $_GET['ec_panel'] == "backup-store" && ( $_GET['ec_action'] == "download_designs" || $_GET['ec_action'] == "download_products" ) ){
  112. if( $_GET['ec_action'] == "download_designs" ){
  113. $zipname = WP_PLUGIN_DIR . "/wp-easycart-data/design.zip";
  114. $zip_shortname = "design.zip";
  115. }else if( $_GET['ec_action'] == "download_products" ){
  116. $zipname = WP_PLUGIN_DIR . "/wp-easycart-data/products.zip";
  117. $zip_shortname = "products.zip";
  118. }
  119. $zip = new ZipArchive;
  120. $zip->open( $zipname, ZipArchive::CREATE );
  121. if( $_GET['ec_action'] == "download_designs" ){
  122. $source = WP_PLUGIN_DIR . "/wp-easycart-data/design/";
  123. }else if( $_GET['ec_action'] == "download_products" ){
  124. $source = WP_PLUGIN_DIR . "/wp-easycart-data/products/";
  125. }
  126. $source = str_replace( '\\', '/', realpath( $source ) );
  127. $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $source ), RecursiveIteratorIterator::SELF_FIRST );
  128. foreach( $files as $file ){
  129. $file = str_replace( '\\', '/', realpath( $file ) );
  130. if( is_dir( $file ) === true ){
  131. $zip->addEmptyDir( str_replace( $source . '/', '', $file . '/' ) );
  132. }else if( is_file( $file ) === true ){
  133. $zip->addFromString( str_replace( $source . '/', '', $file ), file_get_contents( $file ) );
  134. }
  135. }
  136. $zip->close( );
  137. if( file_exists( $zipname ) ){
  138. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0");
  139. header( "Cache-Control: private",false);
  140. header( 'Content-Type: application/zip' );
  141. header( 'Content-Disposition: attachment; filename="' . $zip_shortname . '";' );
  142. header( 'Content-Length: ' . ( string )( filesize( $zipname ) ) );
  143. header( "Content-Transfer-Encoding: binary" );
  144. header( 'Expires: 0');
  145. header( 'Cache-Control: private');
  146. header( 'Pragma: private');
  147. ob_clean();
  148. flush();
  149. readfile( $zipname );
  150. unlink( $zipname );
  151. }else{
  152. exit( "Could not find the zip to be downloaded" );
  153. }
  154. }else if( is_admin( ) && isset( $_GET['page'] ) && isset( $_GET['ec_page'] ) && isset( $_GET['ec_panel'] ) && isset( $_GET['ec_action'] ) && $_GET['page'] == "ec_adminv2" && $_GET['ec_page'] == "dashboard" && $_GET['ec_panel'] == "backup-store" && $_GET['ec_action'] == "download_db" ){
  155. $mysql_database = DB_NAME;
  156. $db_selected = mysql_select_db($mysql_database);
  157. // Get the contents
  158. $file_contents = ec_mysqldump( $mysql_database );
  159. $sql_shortname = "Storefront_Backup_" . date( 'Y_m_d' ) . ".sql";
  160. $sqlname = WP_PLUGIN_DIR . "/wp-easycart-data/" . $sql_shortname;
  161. file_put_contents( $sqlname, $file_contents );
  162. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0");
  163. header( "Content-type: text/plain");
  164. header( 'Content-Disposition: attachment; filename=' . $sql_shortname );
  165. header( 'Content-Length: ' . ( string )( filesize( $sqlname ) ) );
  166. header( "Content-Transfer-Encoding: binary" );
  167. header( 'Expires: 0');
  168. header( 'Cache-Control: private');
  169. header( 'Pragma: private');
  170. readfile( $sqlname );
  171. unlink( $sqlname );
  172. // Stop the page execution so that it doesn't print HTML to the file accidently
  173. die();
  174. }
  175. }
  176. //store settings menu
  177. function ec_settings_page_callback(){
  178. include("ec_install.php");
  179. }
  180. function ec_install_page_callback(){
  181. include("ec_install.php");
  182. }
  183. function ec_setup_page_callback(){
  184. include("store_setup.php");
  185. }
  186. function ec_payment_page_callback(){
  187. include("payment.php");
  188. }
  189. function ec_social_icons_page_callback(){
  190. include("social_icons.php");
  191. }
  192. function ec_language_page_callback(){
  193. include("language.php");
  194. }
  195. //administration menu
  196. function ec_administration_callback() {
  197. include("demos.php");
  198. }
  199. function ec_admin_console_page_callback() {
  200. include("admin_console.php");
  201. }
  202. function ec_demos_callback() {
  203. include("demos.php");
  204. }
  205. function ec_users_guide_callback() {
  206. include("users_guide.php");
  207. }
  208. //store design menu
  209. function ec_base_design_page_callback(){
  210. include("base_design.php");
  211. }
  212. // Admin per theme function is in wpeasycart.php
  213. //store checklist menu
  214. function ec_checklist_page_callback(){
  215. include("checklist.php");
  216. }
  217. //store v2 admin menu item
  218. function ec_adminv2_page_callback( ){
  219. include( "admin_v2.php" );
  220. }
  221. function ec_mysqldump( $mysql_database ){
  222. $return_string = "";
  223. $return_string .= "/*MySQL Dump File*/\n";
  224. $sql = "show tables;";
  225. $result = mysql_query($sql);
  226. if( $result ){
  227. while( $row = mysql_fetch_row( $result ) ){
  228. $return_string .= ec_mysqldump_table_structure( $row[0] );
  229. $return_string .= ec_mysqldump_table_data( $row[0] );
  230. }
  231. }else{
  232. $return_string .= "/* no tables in $mysql_database */\n";
  233. }
  234. mysql_free_result( $result );
  235. return $return_string;
  236. }
  237. function ec_mysqldump_table_structure( $table ){
  238. $return_string = "";
  239. $return_string .= "/* Table structure for table `$table` */\n";
  240. $return_string .= "DROP TABLE IF EXISTS `$table`;\n\n";
  241. $sql = "show create table `$table`; ";
  242. $result = mysql_query( $sql );
  243. if( $result ){
  244. if( $row = mysql_fetch_assoc( $result ) ){
  245. $return_string .= $row['Create Table'].";\n\n";
  246. }
  247. }
  248. mysql_free_result( $result );
  249. return $return_string;
  250. }
  251. function ec_mysqldump_table_data( $table ){
  252. $return_string = "";
  253. $sql = "select * from `$table`;";
  254. $result = mysql_query( $sql );
  255. if( $result ){
  256. $num_rows = mysql_num_rows( $result );
  257. $num_fields = mysql_num_fields( $result );
  258. if( $num_rows > 0 ){
  259. $return_string .= "/* dumping data for table `$table` */\n";
  260. $field_type = array( );
  261. $i = 0;
  262. while( $i < $num_fields ){
  263. $meta = mysql_fetch_field( $result, $i );
  264. array_push( $field_type, $meta->type );
  265. $i++;
  266. }
  267. $return_string .= "insert into `$table` values\n";
  268. $index = 0;
  269. while( $row = mysql_fetch_row( $result ) ){
  270. $return_string .= "(";
  271. for( $i = 0; $i < $num_fields; $i++ ){
  272. if( is_null( $row[$i] ) )
  273. $return_string .= "null";
  274. else{
  275. switch( $field_type[$i] ){
  276. case 'int':
  277. $return_string .= $row[$i];
  278. break;
  279. case 'string':
  280. case 'blob' :
  281. default:
  282. $return_string .= "'".mysql_real_escape_string($row[$i])."'";
  283. }
  284. }
  285. if( $i < $num_fields - 1 )
  286. $return_string .= ",";
  287. }
  288. $return_string .= ")";
  289. if( $index < $num_rows - 1 )
  290. $return_string .= ",";
  291. else
  292. $return_string .= ";";
  293. $return_string .= "\n";
  294. $index++;
  295. }
  296. }
  297. }
  298. mysql_free_result($result);
  299. $return_string .= "\n";
  300. return $return_string;
  301. }
  302. function ec_post_save_permalink_structure( $post_id ) {
  303. global $wp_rewrite;
  304. $wp_rewrite->flush_rules();
  305. }
  306. function ec_post_save_match_store_meta( $post_id ) {
  307. //If we are matching post meta, lets do it here for store page only!
  308. $selected_store_id = get_option( 'ec_option_storepage' );
  309. $using_meta_match = get_option( 'ec_option_match_store_meta' );
  310. if( $using_meta_match && $selected_store_id == $post_id ){
  311. //Get the store page meta
  312. $store_meta = get_post_meta( $post_id );
  313. //Get the posts for the store
  314. $args = array( 'post_type' => 'ec_store' );
  315. $my_query = new WP_Query( $args );
  316. foreach( $my_query->posts as $post ){
  317. //Get the post meta for deletion if needed
  318. $post_meta = get_post_meta( $post->ID );
  319. //Delete each meta for this post
  320. foreach( $post_meta as $key => $meta ){
  321. delete_post_meta( $post->ID, $key );
  322. }
  323. //Add each store meta to this post
  324. foreach( $store_meta as $key => $meta ){
  325. //We need to check if unseriablizable and deal with it accordingly
  326. $meta_arr = @unserialize( $meta[0] );
  327. if( $meta_arr !== false ){
  328. add_post_meta( $post->ID, $key, $meta_arr );
  329. }else{
  330. add_post_meta( $post->ID, $key, $meta[0] );
  331. }
  332. }
  333. }
  334. }
  335. }
  336. /***********************************************************************************
  337. * BEGIN FUNCTIONS FOR THE SHORTCODE EDITOR
  338. ************************************************************************************/
  339. /***********************************************************************************
  340. * BASIC SHORTCODE EDITOR FUNCTIONS
  341. ************************************************************************************/
  342. function ec_add_editor_buttons( ){
  343. add_filter( "mce_external_plugins", "ec_add_buttons" );
  344. add_filter( 'mce_buttons', 'ec_register_buttons' );
  345. }
  346. function ec_add_buttons( $plugin_array ) {
  347. $plugin_array['wpeasycart'] = plugins_url() . '/wp-easycart/inc/admin/assets/js/editor.js';
  348. return $plugin_array;
  349. }
  350. function ec_register_buttons( $buttons ) {
  351. array_push( $buttons, 'ec_show_editor' );
  352. return $buttons;
  353. }
  354. function ec_print_editor( ){
  355. echo "<div class=\"ec_editor_box_container\" id=\"ec_editor_window\">";
  356. echo "<a href=\"#\" class=\"ec_editor_close\" onclick=\"return ec_close_editor( );\"><span>x</span></a>";
  357. echo "<h3 class=\"ec_editor_heading\">Insert EasyCart Shortcodes</h3>";
  358. echo "<div class=\"ec_editor_inner_container\">";
  359. // Start Container Inner
  360. ec_print_editor_shortcode_menu( ); // Shortcode Menu
  361. // Store shortcode, no options, nothing needed
  362. ec_print_editor_product_menu( );// Product Menu Store Shortcode Panel
  363. ec_print_editor_product_category( );// Product Category Store Shortcode Panel
  364. ec_print_editor_manufacturer_group( );// Manufacturer Group Store Shortcode Panel
  365. ec_print_editor_product_details( );// Product Details Store Shortcode Panel
  366. // Cart shortcode, no options, nothing needed
  367. // Account shortcode, no options, nothing needed
  368. ec_print_editor_single_product( );// Single Product Shortcode Panel
  369. ec_print_editor_multiple_products( );// Multiple Products Shortcode Panel
  370. ec_print_editor_add_to_cart( );// Add to Cart Shortcode Panel
  371. // Cart Display shortcode, no options, nothing needed
  372. ec_print_editor_membership_content( );// Add to Cart Shortcode Panel
  373. // End Container Inner
  374. echo "</div>";
  375. echo "</div>";
  376. echo "<div class=\"ec_editor_overlay\" id=\"ec_editor_bg\"></div>";
  377. }
  378. // Shortcode Menu
  379. function ec_print_editor_shortcode_menu( ){
  380. echo "<ul class=\"ec_column_holder\" id=\"ec_shortcode_menu\">";
  381. echo "<li data-ecshortcode=\"ec_store\"><div>STORE</div></li>";
  382. echo "<li data-ecshortcode=\"ec_menu\"><div>PRODUCT MENU</div></li>";
  383. echo "<li data-ecshortcode=\"ec_category\"><div>PRODUCT CATEGORY</div></li>";
  384. echo "<li data-ecshortcode=\"ec_manufacturer\"><div>MANUFACTURER GROUP</div></li>";
  385. echo "<li data-ecshortcode=\"ec_productdetails\"><div>PRODUCT DETAILS</div></li>";
  386. echo "<li data-ecshortcode=\"ec_cart\"><div>CART</div></li>";
  387. echo "<li data-ecshortcode=\"ec_account\"><div>ACCOUNT</div></li>";
  388. echo "<li data-ecshortcode=\"ec_singleitem\"><div>SINGLE ITEM</div></li>";
  389. echo "<li data-ecshortcode=\"ec_selecteditems\"><div>SELECT ITEMS</div></li>";
  390. echo "<li data-ecshortcode=\"ec_addtocart\"><div>ADD TO CART BUTTON</div></li>";
  391. echo "<li data-ecshortcode=\"ec_cartdisplay\"><div>CART DISPLAY</div></li>";
  392. echo "<li data-ecshortcode=\"ec_membership\"><div>MEMBERSHIP CONTENT</div></li>";
  393. echo "</ul>";
  394. }
  395. /***********************************************************************************
  396. * BEGIN FUNCTIONS FOR THE PRODUCT MENU PANEL
  397. ************************************************************************************/
  398. // Product Menu Shortcode Creator Panel
  399. function ec_print_editor_product_menu( ){
  400. echo "<div class=\"ec_editor_panel\" id=\"ec_product_menu\">";
  401. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  402. echo "<div class=\"ec_editor_error\" id=\"ec_product_menu_error\"><span>Please select a menu item at the minimum</span></div>";
  403. echo "<div class=\"ec_editor_help_text\">To display a product menu item page, select a menu item below. If you want to display a sub menu or a subsub menu, then select the menu, followed by the submenu and/or the subsubmenu.</div>";
  404. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Menu:</span><span id=\"ec_editor_menu_holder\" class=\"ec_editor_select_row_input\">";
  405. ec_print_menu_select( 'ec_editor_menu_select' );
  406. echo "</div>";
  407. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Sub Menu:</span><span id=\"ec_editor_submenu_holder\" class=\"ec_editor_select_row_input\">";
  408. ec_print_submenu_select( 'ec_editor_submenu_select', 0 );
  409. echo "</span></div>";
  410. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">SubSub Menu:</span><span id=\"ec_editor_subsubmenu_holder\" class=\"ec_editor_select_row_input\">";
  411. ec_print_subsubmenu_select( 'ec_editor_subsubmenu_select', 0 );
  412. echo "</span></div>";
  413. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_product_menu\" class=\"ec_editor_button\"></span></div>";
  414. echo "</div>";
  415. }
  416. // Print all main menu items in a select box
  417. function ec_print_menu_select( $id ){
  418. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\" onchange=\"ec_editor_select_menu_change( );\">";
  419. $db = new ec_db( );
  420. $menu_items = $db->get_menulevel1_items( );
  421. if( count( $menu_items ) > 0 ){
  422. echo "<option value=\"0\">Select a Menu Item</option>";
  423. foreach( $menu_items as $menu ){
  424. echo "<option value=\"" . $menu->menulevel1_id . "\">" . $menu->menu1_name . "</option>";
  425. }
  426. }else{
  427. echo "<option value=\"0\">No Menu Items Exist</option>";
  428. }
  429. echo "</select>";
  430. }
  431. // Print all sub menu items for a particular menu item in a select box
  432. function ec_print_submenu_select( $id, $menuid ){
  433. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\" onchange=\"ec_editor_select_submenu_change( );\">";
  434. if( $menuid > 0 ){
  435. $db = new ec_db( );
  436. $menu_items = $db->get_menulevel2_items( );
  437. if( count( $menu_items ) > 0 ){
  438. echo "<option value=\"0\">Select a Menu Item (optional)</option>";
  439. foreach( $menu_items as $menu ){
  440. if( $menu->menulevel1_id == $menuid ){
  441. echo "<option value=\"" . $menu->menulevel2_id . "\">" . $menu->menu2_name . "</option>";
  442. }
  443. }
  444. }else{
  445. echo "<option value=\"0\">No SubMenu Items Exist</option>";
  446. }
  447. }else{
  448. echo "<option value=\"0\">No Menu Item Selected</option>";
  449. }
  450. echo "</select>";
  451. }
  452. // Print all sub menu items for a particular menu item in a select box
  453. function ec_print_subsubmenu_select( $id, $submenuid ){
  454. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  455. if( $submenuid > 0 ){
  456. $db = new ec_db( );
  457. $menu_items = $db->get_menulevel3_items( );
  458. if( count( $menu_items ) > 0 ){
  459. echo "<option value=\"0\">Select a SubSub Menu Item (optional)</option>";
  460. foreach( $menu_items as $menu ){
  461. if( $menu->menulevel2_id == $submenuid ){
  462. echo "<option value=\"" . $menu->menulevel3_id . "\">" . $menu->menu3_name . "</option>";
  463. }
  464. }
  465. }else{
  466. echo "<option value=\"0\">No SubSubMenu Items Exist</option>";
  467. }
  468. }else{
  469. echo "<option value=\"0\">No Sub Menu Item Selected</option>";
  470. }
  471. echo "</select>";
  472. }
  473. // Ajax calls
  474. function ec_editor_update_sub_menu( ){
  475. $id = $_POST['id'];
  476. $menuid = $_POST['menuid'];
  477. ec_print_submenu_select( $id, $menuid );
  478. die( );
  479. }
  480. function ec_editor_update_subsub_menu( ){
  481. $id = $_POST['id'];
  482. $submenuid = $_POST['submenuid'];
  483. ec_print_subsubmenu_select( $id, $submenuid );
  484. die( );
  485. }
  486. /***********************************************************************************
  487. * BEGIN FUNCTIONS FOR THE PRODUCT CATEGORY PANEL
  488. ************************************************************************************/
  489. // Product Category Shortcode Creator Panel
  490. function ec_print_editor_product_category( ){
  491. echo "<div class=\"ec_editor_panel\" id=\"ec_product_category\">";
  492. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  493. echo "<div class=\"ec_editor_error\" id=\"ec_product_category_error\"><span>Please select a category item</span></div>";
  494. echo "<div class=\"ec_editor_help_text\">This shortcode displays a category group which can be created in the store admin in the submenu of the products section.</div>";
  495. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Category:</span><span class=\"ec_editor_select_row_input\">";
  496. ec_print_category_select( 'ec_editor_category_select' );
  497. echo "</div>";
  498. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_product_category\" class=\"ec_editor_button\"></span></div>";
  499. echo "</div>";
  500. }
  501. // Print all main menu items in a select box
  502. function ec_print_category_select( $id ){
  503. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  504. $db = new ec_db( );
  505. $category_items = $db->get_category_list( );
  506. if( count( $category_items ) > 0 ){
  507. echo "<option value=\"0\">Select a Category Item</option>";
  508. foreach( $category_items as $category ){
  509. echo "<option value=\"" . $category->category_id . "\">" . $category->category_name . "</option>";
  510. }
  511. }else{
  512. echo "<option value=\"0\">No Category Items Exist</option>";
  513. }
  514. echo "</select>";
  515. }
  516. /***********************************************************************************
  517. * BEGIN FUNCTIONS FOR THE MANUFACTURER GROUP PANEL
  518. ************************************************************************************/
  519. // Product Category Shortcode Creator Panel
  520. function ec_print_editor_manufacturer_group( ){
  521. echo "<div class=\"ec_editor_panel\" id=\"ec_manufacturer_group\">";
  522. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  523. echo "<div class=\"ec_editor_error\" id=\"ec_manufacturer_group_error\"><span>Please select a manufacturer</span></div>";
  524. echo "<div class=\"ec_editor_help_text\">This shortcode displays a manufacturer group, which consists of all products assigned to the selected manufacturer (think of it as a product filter by manufacturer).</div>";
  525. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Manufacturer:</span><span class=\"ec_editor_select_row_input\">";
  526. ec_print_manufacturer_select( 'ec_editor_manufacturer_select' );
  527. echo "</div>";
  528. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_manufacturer_group\" class=\"ec_editor_button\"></span></div>";
  529. echo "</div>";
  530. }
  531. // Print all main menu items in a select box
  532. function ec_print_manufacturer_select( $id ){
  533. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  534. $db = new ec_db( );
  535. $manufacturers = $db->get_manufacturer_list( );
  536. if( count( $manufacturers ) > 0 ){
  537. echo "<option value=\"0\">Select a Manufacturer</option>";
  538. foreach( $manufacturers as $manufacturer ){
  539. echo "<option value=\"" . $manufacturer->manufacturer_id . "\">" . $manufacturer->name . "</option>";
  540. }
  541. }else{
  542. echo "<option value=\"0\">No Manufacturers Exist</option>";
  543. }
  544. echo "</select>";
  545. }
  546. /***********************************************************************************
  547. * BEGIN FUNCTIONS FOR THE PRODUCT DETAILS PANEL
  548. ************************************************************************************/
  549. // Product Category Shortcode Creator Panel
  550. function ec_print_editor_product_details( ){
  551. echo "<div class=\"ec_editor_panel\" id=\"ec_productdetails_menu\">";
  552. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  553. echo "<div class=\"ec_editor_error\" id=\"ec_productdetails_error\"><span>Please Select a Product</span></div>";
  554. echo "<div class=\"ec_editor_help_text\">This shortcode displays a single product's details on the specified page.</div>";
  555. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Product:</span><span class=\"ec_editor_select_row_input\">";
  556. ec_print_productdetails_select( 'ec_editor_productdetails_select' );
  557. echo "</div>";
  558. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_productdetails\" class=\"ec_editor_button\"></span></div>";
  559. echo "</div>";
  560. }
  561. // Print all main menu items in a select box
  562. function ec_print_productdetails_select( $id ){
  563. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  564. $db = new ec_db( );
  565. $products = $db->get_product_list( "", " ORDER BY product.title", "", "" );
  566. if( count( $products ) > 0 ){
  567. echo "<option value=\"0\">Select a Product</option>";
  568. for( $i=0; $i<count( $products ); $i++ ){
  569. echo "<option value=\"" . $products[$i]['model_number'] . "\">" . $products[$i]['title'] . "</option>";
  570. }
  571. }else{
  572. echo "<option value=\"0\">No Products Exist</option>";
  573. }
  574. echo "</select>";
  575. }
  576. /***********************************************************************************
  577. * BEGIN FUNCTIONS FOR THE SINGLE PRODUCT PANEL
  578. ************************************************************************************/
  579. // Product Category Shortcode Creator Panel
  580. function ec_print_editor_single_product( ){
  581. echo "<div class=\"ec_editor_panel\" id=\"ec_single_product\">";
  582. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  583. echo "<div class=\"ec_editor_error\" id=\"ec_single_product_error\"><span>Please Select a Product</span></div>";
  584. echo "<div class=\"ec_editor_help_text\">This shortcode displays a single product with a view details button.</div>";
  585. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Product:</span><span class=\"ec_editor_select_row_input\">";
  586. ec_print_product_select( 'ec_editor_single_product_select' );
  587. echo "</div>";
  588. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Display Type:</span><span class=\"ec_editor_select_row_input\">";
  589. ec_print_product_display_type_select( 'ec_editor_single_product_display_type' );
  590. echo "</div>";
  591. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_single_product\" class=\"ec_editor_button\"></span></div>";
  592. echo "</div>";
  593. }
  594. // Print all main menu items in a select box
  595. function ec_print_product_select( $id ){
  596. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  597. $db = new ec_db( );
  598. $products = $db->get_product_list( "", " ORDER BY product.title", "", "" );
  599. if( count( $products ) > 0 ){
  600. echo "<option value=\"0\">Select a Product</option>";
  601. for( $i=0; $i<count( $products ); $i++ ){
  602. echo "<option value=\"" . $products[$i]['product_id'] . "\">" . $products[$i]['title'] . "</option>";
  603. }
  604. }else{
  605. echo "<option value=\"0\">No Products Exist</option>";
  606. }
  607. echo "</select>";
  608. }
  609. // Print the display types available for the product display
  610. function ec_print_product_display_type_select( $id ){
  611. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  612. echo "<option value=\"1\" selected=\"selected\">Same as Store Product Display</option>";
  613. echo "<option value=\"2\">Same as Product Widget Display</option>";
  614. echo "<option value=\"3\">Custom Display Type 1</option>";
  615. echo "</select>";
  616. }
  617. /***********************************************************************************
  618. * BEGIN FUNCTIONS FOR THE MULTIPLE PRODUCTS PANEL
  619. ************************************************************************************/
  620. // Product Category Shortcode Creator Panel
  621. function ec_print_editor_multiple_products( ){
  622. echo "<div class=\"ec_editor_panel\" id=\"ec_multiple_products\">";
  623. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  624. echo "<div class=\"ec_editor_error\" id=\"ec_multiple_products_error\"><span>Please Select at Least One Product</span></div>";
  625. echo "<div class=\"ec_editor_help_text\">This shortcode displays multiple products that can be selected one at a time. Each is displayed with a view details button.</div>";
  626. echo "<div class=\"ec_editor_multiple_select_row\"><span class=\"ec_editor_select_row_label\">Product:</span><span class=\"ec_editor_select_row_input\">";
  627. ec_print_product_multiple_select( 'ec_editor_multiple_products_select' );
  628. echo "</div>";
  629. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Display Type:</span><span class=\"ec_editor_select_row_input\">";
  630. ec_print_product_display_type_select( 'ec_editor_multiple_products_display_type' );
  631. echo "</div>";
  632. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Columns:</span><span class=\"ec_editor_select_row_input\">";
  633. ec_print_product_columns_select( 'ec_editor_multiple_products_columns' );
  634. echo "</div>";
  635. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_multiple_products\" class=\"ec_editor_button\"></span></div>";
  636. echo "</div>";
  637. }
  638. // Print all main menu items in a select box
  639. function ec_print_product_multiple_select( $id ){
  640. echo "<select multiple=\"multiple\" class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  641. $db = new ec_db( );
  642. $products = $db->get_product_list( "", " ORDER BY product.title", "", "" );
  643. if( count( $products ) > 0 ){
  644. for( $i=0; $i<count( $products ); $i++ ){
  645. echo "<option value=\"" . $products[$i]['product_id'] . "\">" . $products[$i]['title'] . "</option>";
  646. }
  647. }else{
  648. echo "<option value=\"0\">No Products Exist</option>";
  649. }
  650. echo "</select>";
  651. }
  652. function ec_print_product_columns_select( $id ){
  653. echo "<select class=\"ec_editor_select_box\" id=\"" . $id . "\">";
  654. echo "<option value=\"1\">1</option>";
  655. echo "<option value=\"2\">2</option>";
  656. echo "<option value=\"3\" selected=\"selected\">3</option>";
  657. echo "<option value=\"4\">4</option>";
  658. echo "<option value=\"5\">5</option>";
  659. echo "</select>";
  660. }
  661. /***********************************************************************************
  662. * BEGIN FUNCTIONS FOR THE ADD TO CART PANEL
  663. ************************************************************************************/
  664. // Product Category Shortcode Creator Panel
  665. function ec_print_editor_add_to_cart( ){
  666. echo "<div class=\"ec_editor_panel\" id=\"ec_add_to_cart\">";
  667. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  668. echo "<div class=\"ec_editor_error\" id=\"ec_add_to_cart_error\"><span>Please Select a Product</span></div>";
  669. echo "<div class=\"ec_editor_help_text\">This shortcode displays an add to cart button (with options if attached) of a single product.</div>";
  670. echo "<div class=\"ec_editor_select_row\"><span class=\"ec_editor_select_row_label\">Product:</span><span class=\"ec_editor_select_row_input\">";
  671. ec_print_product_select( 'ec_editor_add_to_cart_product_select' );
  672. echo "</div>";
  673. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_add_to_cart\" class=\"ec_editor_button\"></span></div>";
  674. echo "</div>";
  675. }
  676. // Reusing the print product select option
  677. /***********************************************************************************
  678. * BEGIN FUNCTIONS FOR THE MEMBERSHIP CONTENT PANEL
  679. ************************************************************************************/
  680. // Membership Content Creator Panel
  681. function ec_print_editor_membership_content( ){
  682. echo "<div class=\"ec_editor_panel\" id=\"ec_membership_menu\">";
  683. echo "<div class=\"ec_editor_select_row\"><input type=\"button\" value=\"BACK\" class=\"ec_editor_button backlink\"></div>";
  684. echo "<div class=\"ec_editor_error\" id=\"ec_membership_error\"><span>Please Select at Least One Product</span></div>";
  685. echo "<div class=\"ec_editor_help_text\">This shortcode allows you to require a user to be subscribed to a product or one product in a group of products. For example, you could create a single content page that has a bronze, silver, and gold membership level with content for all three, just silver and gold, and just gold. In addition, it gives you an alternate content area</div>";
  686. echo "<div class=\"ec_editor_multiple_select_row\"><span class=\"ec_editor_select_row_label\">Product(s):</span><span class=\"ec_editor_select_row_input\">";
  687. ec_print_product_multiple_select( 'ec_editor_membership_multiple_product_select' );
  688. echo "</div>";
  689. echo "<div class=\"ec_editor_submit_row\"><span class=\"ec_editor_select_row_input\"><input type=\"button\" value=\"ADD SHORTCODE\" id=\"ec_add_membership\" class=\"ec_editor_button\"></span></div>";
  690. echo "</div>";
  691. }
  692. ?>