Guest User

Untitled

a guest
Dec 10th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 141.97 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // include all the core admin ClassiPress files
  5. require_once ('admin-values.php');
  6. require_once ('admin-notices.php');
  7. require_once ('admin-addons.php');
  8. require_once ('admin-updates.php');
  9.  
  10.  
  11. // load and create all the CP admin pages
  12. function appthemes_admin_options() {
  13. global $wpdb, $app_abbr, $app_theme;
  14.  
  15. if ( !current_user_can('manage_options') ) return;
  16.  
  17. add_menu_page($app_theme, $app_theme, 'manage_options', basename(__FILE__), 'cp_dashboard', FAVICON, THE_POSITION );
  18. add_submenu_page( basename(__FILE__), __('Dashboard','appthemes'), __('Dashboard','appthemes'), 'manage_options', basename(__FILE__), 'cp_dashboard' );
  19. add_submenu_page( basename(__FILE__), __('General Settings','appthemes'), __('Settings','appthemes'), 'manage_options', 'settings', 'cp_settings' );
  20. add_submenu_page( basename(__FILE__), __('Emails','appthemes'), __('Emails','appthemes'), 'manage_options', 'emails', 'cp_emails' );
  21. add_submenu_page( basename(__FILE__), __('Pricing Settings','appthemes'), __('Pricing','appthemes'), 'manage_options', 'pricing', 'cp_pricing' );
  22. add_submenu_page( basename(__FILE__), __('Packages','appthemes'), __('Packages','appthemes'), 'manage_options', 'packages', 'cp_ad_packs' );
  23. add_submenu_page( basename(__FILE__), __('Coupons','appthemes'), __('Coupons','appthemes'), 'manage_options', 'coupons', 'cp_coupons' );
  24. add_submenu_page( basename(__FILE__), __('Payment Gateway Options','appthemes'), __('Gateways','appthemes'), 'manage_options', 'gateways', 'cp_gateways' );
  25. add_submenu_page( basename(__FILE__), __('Form Layouts','appthemes'), __('Form Layouts','appthemes'), 'manage_options', 'layouts', 'cp_form_layouts' );
  26. add_submenu_page( basename(__FILE__), __('Custom Fields','appthemes'), __('Custom Fields','appthemes'), 'manage_options', 'fields', 'cp_custom_fields' );
  27. add_submenu_page( basename(__FILE__), __('Transactions','appthemes'), __('Transactions','appthemes'), 'manage_options', 'transactions', 'cp_transactions' );
  28. add_submenu_page( basename(__FILE__), __('System Info','appthemes'), __('System Info','appthemes'), 'manage_options', 'sysinfo', 'cp_system_info' );
  29.  
  30. do_action( 'appthemes_add_submenu_page' );
  31. }
  32. add_action('admin_menu', 'appthemes_admin_options');
  33.  
  34.  
  35.  
  36. // update all the admin options on save
  37. function cp_update_options($options) {
  38. $toolsMessage = '';
  39.  
  40. if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes') {
  41.  
  42. foreach ( $options as $value ) {
  43. if ( isset($_POST[$value['id']]) ) {
  44. //echo $value['id'] . '<-- value ID | ' . $_POST[$value['id']] . '<-- $_POST value ID <br/><br/>'; // FOR DEBUGGING
  45. update_option( $value['id'], appthemes_clean($_POST[$value['id']]) );
  46. } else {
  47. @delete_option( $value['id'] );
  48. }
  49. }
  50.  
  51. // do a separate update for price per cats since it's not in the $options array
  52. if ( isset($_POST['catarray']) ) {
  53. foreach ( $_POST['catarray'] as $key => $value ) {
  54. // echo $key .'<-- key '. $value .'<-- value<br/>'; // FOR DEBUGGING
  55. update_option( $key, appthemes_clean($value) );
  56. }
  57. }
  58.  
  59. // clean all values from the post and store them into a wordpress option as a serialized array of cat ID's
  60. if ( isset($_POST['catreqarray']) ) {
  61. foreach ( $_POST['catreqarray'] as $key => $value ) {
  62. $catreqarray[absint($value)] = '';
  63. }
  64. update_option('cp_required_categories', $catreqarray);
  65. } else if (isset($_POST['cp_required_membership_type'])){
  66. delete_option('cp_required_categories');
  67. }
  68.  
  69. if ( get_option('cp_tools_run_expiredcheck') == 'yes' ) {
  70. update_option('cp_tools_run_expiredcheck', 'no');
  71. cp_check_expired_cron();
  72. $toolsMessage = '';
  73. $toolsMessage .= __('Ads Expired Check was executed.');
  74. }
  75.  
  76. // flush out the cache so changes can be visible
  77. cp_flush_all_cache();
  78.  
  79. echo '<div class="updated"><p>'.__('Your settings have been saved.','appthemes'). ' ' . $toolsMessage . '</p></div>';
  80.  
  81. } elseif ( isset($_POST['submitted']) && $_POST['submitted'] == 'convertToCustomPostType' ) {
  82. update_option('cp_tools_run_convertToCustomPostType', 'no');
  83. $toolsMessage .= cp_convert_posts2Ads();
  84. echo $toolsMessage;
  85. }
  86. }
  87.  
  88. // creates the category checklist box
  89. function cp_category_checklist($checkedcats, $exclude = '') {
  90.  
  91. if (empty($walker) || !is_a($walker, 'Walker'))
  92. $walker = new Walker_Category_Checklist;
  93.  
  94. $args = array();
  95.  
  96. if (is_array( $checkedcats ))
  97. $args['selected_cats'] = $checkedcats;
  98. else
  99. $args['selected_cats'] = array();
  100.  
  101. $args['popular_cats'] = array();
  102. $categories = get_categories( array('hide_empty' => 0,
  103. 'taxonomy' => APP_TAX_CAT,
  104. 'exclude' => $exclude) );
  105.  
  106. return call_user_func_array( array(&$walker, 'walk'), array($categories, 0, $args) );
  107. }
  108.  
  109.  
  110. // this grabs the cats that should be excluded
  111. function cp_exclude_cats ($id = NULL) {
  112. global $wpdb;
  113.  
  114. $output = array();
  115.  
  116. if ( $id )
  117. $sql = $wpdb->prepare( "SELECT form_cats FROM $wpdb->cp_ad_forms WHERE id != %s", $id );
  118. else
  119. $sql = $wpdb->prepare( "SELECT form_cats FROM $wpdb->cp_ad_forms" );
  120.  
  121. $records = $wpdb->get_results( $sql );
  122.  
  123. if ( $records ) :
  124.  
  125. foreach ( $records as $record )
  126. $output[] = implode( ',',unserialize($record->form_cats) );
  127.  
  128. endif;
  129.  
  130. $exclude = cp_unique_str( ',', (join( ',', $output )) );
  131.  
  132. return $exclude;
  133. }
  134.  
  135.  
  136. // find a category match and then output it
  137. function cp_match_cats($form_cats) {
  138. global $wpdb;
  139. $out = array();
  140.  
  141. $terms = get_terms( APP_TAX_CAT, array(
  142. 'include' => $form_cats
  143. ));
  144.  
  145. if ( $terms ) :
  146.  
  147. foreach ( $terms as $term ) {
  148. $out[] = '<a href="edit-tags.php?action=edit&taxonomy='.APP_TAX_CAT.'&post_type='.APP_POST_TYPE.'&tag_ID='. $term->term_id .'">'. $term->name .'</a>';
  149. }
  150.  
  151. endif;
  152.  
  153. return join( ', ', $out );
  154. }
  155.  
  156.  
  157. function cp_unique_str($separator, $str) {
  158.  
  159. $str_arr = explode($separator, $str);
  160. $result = array_unique($str_arr);
  161. $unique_str = implode(',', $result);
  162.  
  163. return $unique_str;
  164. }
  165.  
  166.  
  167. /**
  168. * Take field input label value and make custom name
  169. * Strip out everything excepts chars & numbers
  170. * Used for WP custom field name i.e. Middle Name = cp_middle_name
  171. */
  172. function cp_make_custom_name($cname) {
  173.  
  174. $cname = preg_replace('/[^a-zA-Z0-9\s]/', '', $cname);
  175. $cname = 'cp_' . str_replace(' ', '_', strtolower(substr(appthemes_clean($cname), 0, 30)));
  176.  
  177. return $cname;
  178. }
  179.  
  180. // delete the custom form and the meta custom field data
  181. function cp_delete_form($form_id) {
  182. global $wpdb;
  183.  
  184. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->cp_ad_forms WHERE id = %s", $form_id ) );
  185. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->cp_ad_meta WHERE form_id = %s", $form_id ) );
  186. }
  187.  
  188.  
  189. function cp_admin_formbuilder($results) {
  190. global $wpdb;
  191.  
  192. foreach ( $results as $result ) :
  193. ?>
  194.  
  195. <tr class="even" id="<?php echo $result->meta_id; ?>"><!-- id needed for jquery sortable to work -->
  196. <td style="min-width:100px;"><?php echo esc_html( translate( $result->field_label, 'appthemes' ) ); ?></td>
  197. <td>
  198.  
  199. <?php
  200.  
  201. switch ( $result->field_type ) {
  202.  
  203. case 'text box':
  204. ?>
  205.  
  206. <input name="<?php echo $result->field_name; ?>" type="text" style="min-width:200px;" value="" disabled />
  207.  
  208. <?php
  209. break;
  210.  
  211. case 'text area':
  212.  
  213. ?>
  214.  
  215. <textarea rows="4" cols="23" disabled></textarea>
  216.  
  217. <?php
  218. break;
  219.  
  220. case 'radio':
  221.  
  222. $options = explode( ',', $result->field_values );
  223. foreach ( $options as $label ) {
  224. ?>
  225. <input type="radio" name="radiobutton" value="" disabled />&nbsp;<?php echo $label; ?><br />
  226.  
  227. <?php
  228. }
  229. break;
  230.  
  231. case 'checkbox':
  232.  
  233. $options = explode( ',', $result->field_values );
  234. foreach ( $options as $label ) {
  235. ?>
  236. <input type="checkbox" name="checkbox" value="" disabled />&nbsp;<?php echo $label; ?><br />
  237.  
  238. <?php
  239. }
  240. break;
  241.  
  242. default: // used for drop-downs, radio buttons, and checkboxes
  243. ?>
  244.  
  245. <select name="dropdown">
  246.  
  247. <?php
  248. $options = explode( ',', $result->field_values );
  249.  
  250. foreach ( $options as $option ) {
  251. ?>
  252.  
  253. <option style="min-width:177px" value="<?php echo $option; ?>" disabled><?php echo $option; ?></option>
  254.  
  255. <?php
  256. }
  257. ?>
  258.  
  259. </select>
  260.  
  261. <?php
  262.  
  263. } //end switch
  264. ?>
  265.  
  266. </td>
  267.  
  268. <td style="text-align:center;">
  269.  
  270. <?php
  271. // only show the advanced search checkbox for price, city, and zipcode since they display the sliders
  272. // all other text fields are not intended for advanced search use
  273. $ad_search = '';
  274. if ( $result->field_name == 'cp_price' || $result->field_name == 'cp_city' || $result->field_name == 'cp_zipcode' )
  275. $ad_search = '';
  276. elseif ( $result->field_perm == 1 || $result->field_type == 'text area' || $result->field_type == 'text box' )
  277. $ad_search = 'disabled="disabled"';
  278. ?>
  279.  
  280. <input type="checkbox" name="<?php echo $result->meta_id; ?>[field_search]" id="" <?php if ( $result->field_search ) echo 'checked="yes"' ?> <?php if ( $result->field_search ) echo 'checked="yes"' ?> <?php echo $ad_search; ?> value="1" style="" />
  281.  
  282. </td>
  283.  
  284. <td style="text-align:center;">
  285.  
  286. <input type="checkbox" name="<?php echo $result->meta_id; ?>[field_req]" id="" <?php if ( $result->field_req ) echo 'checked="yes"' ?> <?php if ( $result->field_req ) echo 'checked="yes"' ?> <?php if ( $result->field_perm == 1 ) echo 'disabled="disabled"'; ?> value="1" style="" />
  287. <?php if ($result->field_perm == 1) { ?>
  288. <input type="hidden" name="<?php echo $result->meta_id; ?>[field_req]" checked="yes" value="1" />
  289. <?php } ?>
  290.  
  291. </td>
  292.  
  293. <td style="text-align:center;">
  294.  
  295. <input type="hidden" name="id[]" value="<?php echo $result->meta_id; ?>" />
  296. <input type="hidden" name="<?php echo $result->meta_id; ?>[id]" value="<?php echo $result->meta_id; ?>" />
  297.  
  298. <?php if ( $result->field_perm == 1 ) { ?>
  299. <img src="<?php bloginfo('template_directory'); ?>/images/remove-row-gray.png" alt="<?php _e('Cannot remove from layout','appthemes') ?>" title="<?php _e('Cannot remove from layout','appthemes') ?>" />
  300. <?php } else { ?>
  301. <a onclick="return confirmBeforeRemove();" href="?page=layouts&amp;action=formbuilder&amp;id=<?php echo $result->form_id ?>&amp;del_id=<?php echo $result->meta_id ?>&amp;title=<?php echo urlencode($_GET['title']) ?>"><img src="<?php bloginfo('template_directory'); ?>/images/remove-row.png" alt="<?php _e('Remove from layout','appthemes') ?>" title="<?php _e('Remove from layout','appthemes') ?>" /></a>
  302. <?php } ?>
  303.  
  304. </td>
  305. </tr>
  306.  
  307. <?php
  308. endforeach;
  309.  
  310. }
  311.  
  312. // this creates the default fields when a form layout is created
  313. function cp_add_core_fields($form_id) {
  314. global $wpdb;
  315.  
  316. // check to see if any rows already exist for this form. If so, don't insert any data
  317. $wpdb->get_results( $wpdb->prepare( "SELECT form_id FROM $wpdb->cp_ad_meta WHERE form_id = %s", $form_id ) );
  318.  
  319. // no fields yet so let's add the defaults
  320. if ( $wpdb->num_rows == 0 ) {
  321.  
  322. $insert = "INSERT INTO $wpdb->cp_ad_meta" .
  323. " (form_id, field_id, field_req, field_pos) " .
  324. "VALUES ('"
  325. . $wpdb->escape($form_id). "','"
  326. . $wpdb->escape('1'). "','" // post_title
  327. . $wpdb->escape('1'). "','"
  328. . $wpdb->escape('1')
  329. . "'),"
  330. . "('"
  331. . $wpdb->escape($form_id). "','"
  332. . $wpdb->escape('2'). "','" // cp_price
  333. . $wpdb->escape('1'). "','"
  334. . $wpdb->escape('2')
  335. . "'),"
  336. . "('"
  337. . $wpdb->escape($form_id). "','"
  338. . $wpdb->escape('3'). "','" // cp_street
  339. . $wpdb->escape('1'). "','"
  340. . $wpdb->escape('3')
  341. . "'),"
  342. . "('"
  343. . $wpdb->escape($form_id). "','"
  344. . $wpdb->escape('4'). "','" // cp_city
  345. . $wpdb->escape('1'). "','"
  346. . $wpdb->escape('4')
  347. . "'),"
  348. . "('"
  349. . $wpdb->escape($form_id). "','"
  350. . $wpdb->escape('5'). "','" // cp_state
  351. . $wpdb->escape('1'). "','"
  352. . $wpdb->escape('5')
  353. . "'),"
  354. . "('"
  355. . $wpdb->escape($form_id). "','"
  356. . $wpdb->escape('6'). "','" // cp_country
  357. . $wpdb->escape('1'). "','"
  358. . $wpdb->escape('6')
  359. . "'),"
  360. . "('"
  361. . $wpdb->escape($form_id). "','"
  362. . $wpdb->escape('7'). "','" // cp_zipcode
  363. . $wpdb->escape('1'). "','"
  364. . $wpdb->escape('7')
  365. . "'),"
  366. . "('"
  367. . $wpdb->escape($form_id). "','"
  368. . $wpdb->escape('8'). "','" // tags_input
  369. . $wpdb->escape('1'). "','"
  370. . $wpdb->escape('8')
  371. . "'),"
  372. . "('"
  373. . $wpdb->escape($form_id). "','"
  374. . $wpdb->escape('9'). "','" // post_content
  375. . $wpdb->escape('1'). "','"
  376. . $wpdb->escape('9')
  377. . "')";
  378.  
  379. $results = $wpdb->query( $insert );
  380.  
  381. }
  382. }
  383.  
  384.  
  385. function cp_admin_db_fields($options, $cp_table, $cp_id) {
  386. global $wpdb;
  387.  
  388. // gat all the admin fields
  389. $results = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM ". $wpdb->prefix . $cp_table . " WHERE ". $cp_id ." = %d", $_GET['id'] ) );
  390.  
  391. // If the pack has a type, check if it satisfies.
  392. if( isset( $results->pack_type ) && strpos( $results->pack_type, "required_" ) === 0 ){
  393. $results->pack_satisfies_required = "required_";
  394. $results->pack_type = mb_substr($results->pack_type, 9, strlen($results->pack_type));
  395. }else{
  396. $results->pack_satisfies_required = "";
  397. }
  398.  
  399. ?>
  400.  
  401. <table class="widefat fixed" id="tblspacer" style="width:850px;">
  402.  
  403. <?php
  404.  
  405. foreach ( $options as $value ) {
  406.  
  407. if ( $results ) {
  408.  
  409. // foreach ($results as $result):
  410.  
  411. // check to prevent "Notice: Undefined property: stdClass::" error when php strict warnings is turned on
  412. if ( !isset($results->field_type) ) $field_type = ''; else $field_type = $results->field_type;
  413. if ( !isset($results->field_perm) ) $field_perm = ''; else $field_perm = $results->field_perm;
  414.  
  415. switch($value['type']) {
  416.  
  417. case 'title':
  418. ?>
  419.  
  420. <thead>
  421. <tr>
  422. <th scope="col" width="200px"><?php echo $value['name'] ?></th><th scope="col">&nbsp;</th>
  423. </tr>
  424. </thead>
  425.  
  426. <?php
  427.  
  428. break;
  429.  
  430. case 'text':
  431.  
  432. ?>
  433.  
  434. <tr id="<?php echo $value['id'] ?>_row" <?php if ($value['vis'] == '0') echo ' style="display:none;"'; ?>>
  435. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  436. <td class="forminp"><input name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" type="<?php echo $value['type'] ?>" style="<?php echo $value['css'] ?>" value="<?php echo $results->$value['id'] ?>" <?php if ($value['req']) { ?> class="required <?php if (!empty($value['altclass'])) echo $value['altclass'] ?>" <?php } ?><?php if ($value['min']) ?> minlength="<?php echo $value['min'] ?>" <?php if($value['id'] == 'field_name') { ?>readonly="readonly"<?php } ?> /><br /><small><?php echo $value['desc'] ?></small></td>
  437. </tr>
  438.  
  439. <?php
  440.  
  441. break;
  442.  
  443. case 'select':
  444.  
  445. ?>
  446.  
  447. <tr id="<?php echo $value['id'] ?>_row">
  448. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  449. <td class="forminp"><select <?php if ($value['js']) echo $value['js']; ?> <?php if(($field_perm == 1) || ($field_perm == 2)) { ?>DISABLED<?php } ?> name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>">
  450.  
  451. <?php foreach ( $value['options'] as $key => $val ) { ?>
  452.  
  453. <option value="<?php echo $key ?>"<?php if (isset($results->$value['id']) && $results->$value['id'] == $key) { ?> selected="selected" <?php $field_type_out = $field_type; } ?>><?php echo $val; ?></option>
  454.  
  455. <?php } ?>
  456.  
  457. </select><br />
  458. <small><?php echo $value['desc'] ?></small>
  459.  
  460. <?php
  461. // have to submit this field as a hidden value if perms are 1 or 2 since the DISABLED option won't pass anything into the $_POST
  462. if ( ($field_perm == 1) || ($field_perm == 2) ) { ?><input type="hidden" name="<?php echo $value['id'] ?>" value="<?php echo $field_type_out; ?>" /><?php } ?>
  463.  
  464. </td>
  465. </tr>
  466.  
  467. <?php
  468.  
  469. break;
  470.  
  471. case 'textarea':
  472.  
  473. ?>
  474.  
  475. <tr id="<?php echo $value['id'] ?>_row"<?php if($value['id'] == 'field_values') { ?> style="display: none;" <?php } ?>>
  476. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  477. <td class="forminp"><textarea <?php if((($field_perm == 1) || ($field_perm == 2)) && ($value['id'] != 'field_tooltip') && $value['id'] != 'field_values') { ?>readonly="readonly"<?php } ?> name="<?php echo $value['id']?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>"><?php echo $results->$value['id'] ?></textarea>
  478. <br /><small><?php echo $value['desc'] ?></small></td>
  479. </tr>
  480.  
  481. <?php
  482.  
  483. break;
  484.  
  485. case 'checkbox':
  486. ?>
  487.  
  488. <tr id="<?php echo $value['id'] ?>_row">
  489. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  490. <td class="forminp"><input type="checkbox" name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" value="1" style="<?php echo $value['css']?>" <?php if($results->$value['id']) { ?>checked="checked"<?php } ?> />
  491. <br /><small><?php echo $value['desc'] ?></small>
  492. </td>
  493. </tr>
  494.  
  495. <?php
  496. break;
  497.  
  498. case 'cat_checklist':
  499.  
  500. ?>
  501.  
  502. <tr id="<?php echo $value['id'] ?>_row">
  503. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  504. <td class="forminp">
  505. <div id="categorydiv">
  506. <div class="tabs-panel" id="categories-all" style="<?php echo $value['css'] ?>">
  507. <ul class="list:category categorychecklist form-no-clear" id="categorychecklist">
  508.  
  509. <?php echo cp_category_checklist( unserialize($results->form_cats),(cp_exclude_cats($results->id)) ); ?>
  510.  
  511. </ul>
  512. </div>
  513. </div>
  514. <br /><small><?php echo $value['desc'] ?></small>
  515. </td>
  516. </tr>
  517.  
  518. <?php
  519.  
  520. break;
  521.  
  522.  
  523. } // end switch
  524.  
  525. } // end $results
  526.  
  527. } // endforeach
  528.  
  529. ?>
  530.  
  531. </table>
  532.  
  533. <?php
  534. }
  535.  
  536.  
  537. function cp_admin_fields($options) {
  538. global $shortname, $app_abbr;
  539. ?>
  540.  
  541.  
  542. <div id="tabs-wrap">
  543.  
  544.  
  545. <?php
  546.  
  547. // first generate the page tabs
  548. $counter = 0;
  549.  
  550. echo '<ul class="tabs">'. "\n";
  551. foreach ( $options as $value ) {
  552.  
  553. if ( in_array('tab', $value) ) :
  554. echo '<li><a href="#'.$value['type'].$counter.'">'.$value['tabname'].'</a></li>'. "\n";
  555. $counter = $counter + 1;
  556. endif;
  557.  
  558. }
  559. echo '</ul>'. "\n\n";
  560.  
  561.  
  562. // now loop through all the options
  563. $counter = 0;
  564. $table_width = get_option('cp_table_width');
  565.  
  566. foreach ( $options as $value ) {
  567.  
  568. switch ( $value['type'] ) {
  569.  
  570. case 'tab':
  571.  
  572. echo '<div id="'.$value['type'].$counter.'">'. "\n\n";
  573. echo '<table class="widefat fixed" style="width:'.$table_width.'; margin-bottom:20px;">'. "\n\n";
  574.  
  575. break;
  576.  
  577. case 'notab':
  578.  
  579. echo '<table class="widefat fixed" style="width:'.$table_width.'; margin-bottom:20px;">'. "\n\n";
  580.  
  581. break;
  582.  
  583. case 'title':
  584. ?>
  585.  
  586. <thead><tr><th scope="col" width="200px"><?php echo $value['name'] ?></th><th scope="col"><?php if ( isset( $value['desc'] ) ) echo $value['desc'] ?>&nbsp;</th></tr></thead>
  587.  
  588. <?php
  589. break;
  590.  
  591. case 'text':
  592. ?>
  593.  
  594. <?php if ( $value['id'] <> 'field_name' ) { // don't show the meta name field used by WP. This is automatically created by CP. ?>
  595. <tr <?php if ($value['vis'] == '0') { ?>id="<?php if ( !empty($value['visid']) ) { echo $value['visid']; } else { echo 'field_values'; } ?>" style="display:none;"<?php } else { ?>id="<?php echo $value['id'] ?>_row"<?php } ?>>
  596. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  597. <td class="forminp"><input name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" type="<?php echo $value['type'] ?>" style="<?php echo $value['css'] ?>" value="<?php if (get_option( $value['id'])) echo get_option( $value['id'] ); else echo $value['std'] ?>"<?php if ($value['req']) { ?> class="required <?php if ( !empty($value['altclass']) ) echo $value['altclass'] ?>" <?php } ?> <?php if ( $value['min'] ) { ?> minlength="<?php echo $value['min'] ?>"<?php } ?> /><br /><small><?php echo $value['desc'] ?></small></td>
  598. </tr>
  599. <?php } ?>
  600.  
  601. <?php
  602. break;
  603.  
  604. case 'select':
  605. ?>
  606.  
  607. <tr id="<?php echo $value['id'] ?>_row">
  608. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  609. <td class="forminp"><select <?php if ( !empty( $value['js'] ) ) echo $value['js']; ?> name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>"<?php if ( $value['req'] ) { ?> class="required"<?php } ?>>
  610.  
  611. <?php
  612. foreach ($value['options'] as $key => $val) {
  613. ?>
  614.  
  615. <option value="<?php echo $key ?>" <?php if ( get_option($value['id']) == $key ) { ?> selected="selected" <?php } ?>><?php echo ucfirst($val) ?></option>
  616.  
  617. <?php
  618. }
  619. ?>
  620.  
  621. </select><br /><small><?php echo $value['desc'] ?></small>
  622. </td>
  623. </tr>
  624.  
  625. <?php
  626. break;
  627.  
  628. case 'checkbox':
  629. ?>
  630.  
  631. <tr id="<?php echo $value['id'] ?>_row">
  632. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  633. <td class="forminp"><input type="checkbox" name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" value="true" style="<?php echo $value['css']?>" <?php if(get_option($value['id'])) { ?>checked="checked"<?php } ?> />
  634. <br /><small><?php echo $value['desc'] ?></small>
  635. </td>
  636. </tr>
  637.  
  638. <?php
  639. break;
  640.  
  641. case 'textarea':
  642. ?>
  643. <tr id="<?php echo $value['id'] ?>_row"<?php if ( $value['id'] == 'field_values' ) { ?> style="display: none;" <?php } ?>>
  644. <td class="titledesc"><?php if ( $value['tip'] ) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  645. <td class="forminp">
  646. <textarea name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>" <?php if ($value['req']) { ?> class="required" <?php } ?><?php if ( $value['min'] ) { ?> minlength="<?php echo $value['min'] ?>"<?php } ?>><?php if ( get_option($value['id']) ) echo stripslashes( get_option($value['id']) ); else echo $value['std']; ?></textarea>
  647. <br /><small><?php echo $value['desc'] ?></small>
  648. </td>
  649. </tr>
  650.  
  651. <?php
  652. break;
  653.  
  654. case 'cat_checklist':
  655. ?>
  656.  
  657. <tr id="<?php echo $value['id'] ?>_row">
  658. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  659. <td class="forminp">
  660. <div id="categorydiv">
  661. <div class="tabs-panel" id="categories-all" style="<?php echo $value['css'] ?>">
  662. <ul class="list:category categorychecklist form-no-clear" id="categorychecklist">
  663. <?php $catcheck = cp_category_checklist(0,cp_exclude_cats()); ?>
  664. <?php if($catcheck) echo $catcheck; else wp_die( '<p style="color:red;">' .__('All your categories are currently being used. You must remove at least one category from another form layout before you can continue.','appthemes') .'</p>' ); ?>
  665. </ul>
  666. </div>
  667. </div>
  668. <br /><small><?php echo $value['desc'] ?></small>
  669. </td>
  670. </tr>
  671.  
  672. <?php
  673. break;
  674.  
  675. case 'upload':
  676. ?>
  677. <tr>
  678. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  679. <td class="forminp">
  680. <input id="<?php echo $value['id'] ?>" class="upload_image_url" type="text" style="<?php echo $value['css'] ?>" name="<?php echo $value['id'] ?>" value="<?php if (get_option( $value['id'])) echo get_option( $value['id'] ); else echo $value['std'] ?>" />
  681. <input id="upload_image_button" class="upload_button button" rel="<?php echo $value['id'] ?>" type="button" value="<?php _e('Upload Image', 'appthemes') ?>" />
  682. <?php if (get_option( $value['id'])){ ?>
  683. <input name="<?php echo $value['id'] ?>" value="Clear Image" id="delete_image_button" class="delete_button button" rel="<?php echo $value['id'] ?>" type="button" />
  684. <?php } ?>
  685. <br /><small><?php echo $value['desc'] ?></small>
  686. <div id="<?php echo $value['id'] ?>_image" class="<?php echo $value['id'] ?>_image upload_image_preview"><?php if (get_option( $value['id'])) echo '<img src="' .get_option( $value['id'] ) . '" />'; ?></div>
  687.  
  688. </td>
  689. </tr>
  690.  
  691. <?php
  692. break;
  693.  
  694. case 'logo':
  695. ?>
  696. <tr id="<?php echo $value['id'] ?>_row">
  697. <td class="titledesc"><?php echo $value['name'] ?></td>
  698. <td class="forminp">&nbsp;</td>
  699. </tr>
  700.  
  701. <?php
  702. break;
  703.  
  704. case 'price_per_cat':
  705. ?>
  706. <tr id="<?php echo $value['id'] ?>_row" class="cat-row">
  707. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  708.  
  709. <td class="forminp">
  710.  
  711. <table style="width:100%;">
  712.  
  713. <?php
  714.  
  715. $categories = get_categories('orderby=name&order=asc&hide_empty=0&taxonomy='.APP_TAX_CAT);
  716. $i = 0;
  717.  
  718. foreach ($categories as $cat) {
  719.  
  720. if (($i % 2) == 0) { ?>
  721. <tr>
  722. <?php
  723. }
  724.  
  725. // if the category price is empty, put a zero in it so it doesn't error out
  726. $cat_price = get_option('cp_cat_price_'.$cat->cat_ID);
  727. if ($cat_price == '') {
  728. $cat_price = '0';
  729. }
  730. ?>
  731.  
  732. <td nowrap style="padding-top:15px; text-align: right;"><?php echo $cat->cat_name; ?>:</td>
  733. <td nowrap style="color:#bbb;"><input name="catarray[cp_cat_price_<?php echo $cat->cat_ID; ?>]" type="text" size="10" maxlength="100" value="<?php echo $cat_price ?>" />&nbsp;<?php echo get_option($app_abbr.'_curr_pay_type') ?></td>
  734. <td cellspan="2" width="100">&nbsp;</td>
  735.  
  736. <?php
  737. if (($i % 2) != 0) { ?>
  738. </tr>
  739. <?php
  740. }
  741.  
  742. $i++;
  743.  
  744. } // end foreach
  745. ?>
  746.  
  747. </table>
  748.  
  749. </td>
  750. </tr>
  751.  
  752.  
  753. <?php
  754. break;
  755.  
  756. case 'required_per_cat':
  757. ?>
  758. <tr id="<?php echo $value['id'] ?>_row" class="cat-row">
  759. <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" tabindex="99"><div class="helpico"></div></a><?php } ?><?php echo $value['name'] ?>:</td>
  760.  
  761. <td class="forminp">
  762.  
  763. <table style="width:100%;">
  764.  
  765. <?php
  766.  
  767. $categories = get_categories('orderby=name&order=asc&hide_empty=0&taxonomy='.APP_TAX_CAT);
  768. $required_categories = get_option('cp_required_categories');
  769. $i = 0;
  770.  
  771. foreach ($categories as $cat) {
  772.  
  773. if (($i % 2) == 0) { ?>
  774. <tr>
  775. <?php
  776. }
  777.  
  778. ?>
  779.  
  780. <td nowrap style="padding-top:15px; text-align: right;"><?php echo $cat->cat_name; ?>:</td>
  781. <td nowrap style="color:#bbb;"><input name="catreqarray[cp_cat_req_<?php echo $cat->cat_ID; ?>]" type="checkbox" value="<?php echo $cat->cat_ID; ?>" <?php if(isset($required_categories[$cat->cat_ID])) echo 'checked="checked"'; ?> /></td>
  782. <td cellspan="2" width="100">&nbsp;</td>
  783.  
  784. <?php
  785. if (($i % 2) != 0) { ?>
  786. </tr>
  787. <?php
  788. }
  789.  
  790. $i++;
  791.  
  792. } // end foreach
  793. ?>
  794.  
  795. </table>
  796.  
  797. </td>
  798. </tr>
  799.  
  800.  
  801. <?php
  802. break;
  803.  
  804. case 'tabend':
  805.  
  806. echo '</table>'. "\n\n";
  807. echo '</div> <!-- #tab'.$counter.' -->'. "\n\n";
  808. $counter = $counter + 1;
  809.  
  810. break;
  811.  
  812. case 'notabend':
  813.  
  814. echo '</table>'. "\n\n";
  815.  
  816. break;
  817.  
  818. } // end switch
  819.  
  820. } // end foreach
  821. ?>
  822.  
  823. </div> <!-- #tabs-wrap -->
  824.  
  825. <?php
  826. }
  827.  
  828.  
  829. do_action( 'appthemes_add_submenu_page_content' );
  830.  
  831.  
  832. function cp_dashboard() {
  833. global $wpdb, $app_edition, $app_rss_feed;
  834. global $app_twitter_rss_feed, $app_forum_rss_feed, $options_dashboard;
  835.  
  836. $date_today = date('Y-m-d');
  837. $date_yesterday = date('Y-m-d', strtotime('-1 days'));
  838.  
  839. $ad_counts = wp_count_posts( APP_POST_TYPE );
  840. $ad_count_live = $ad_counts->publish;
  841. $ad_count_pending = $ad_counts->pending;
  842. $capabilities_meta = $wpdb->prefix . 'c
  843. tabstabs apabilities';
  844.  
  845. $ad_rev_total = $wpdb->get_var( $wpdb->prepare( "SELECT sum(mc_gross) FROM $wpdb->cp_order_info" ) );
  846. $customers_today = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = %s AND ($wpdb->usermeta.meta_value NOT LIKE %s) AND $wpdb->users.user_registered >= %s", $capabilities_meta, '%administrator%', $date_today ) );
  847. $customers_yesterday = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = %s AND ($wpdb->usermeta.meta_value NOT LIKE %s) AND $wpdb->users.user_registered BETWEEN %s AND %s", $capabilities_meta, '%administrator%', $date_yesterday, $date_today ) );
  848. $countusers = count_users();
  849. ?>
  850.  
  851.  
  852. <div class="wrap">
  853. <div class="icon32" id="icon-themes"><br /></div>
  854. <h2><?php _e('ClassiPress Dashboard', 'appthemes') ?></h2>
  855.  
  856. <?php cp_admin_info_box(); ?>
  857.  
  858. <div class="dash-left metabox-holder">
  859.  
  860. <div class="dash-wrap">
  861.  
  862. <div class="postbox">
  863.  
  864. <div class="statsico"></div>
  865. <h3 class="hndle"><span><?php _e('ClassiPress Info', 'appthemes') ?></span></h3>
  866.  
  867. <div class="inside" id="boxy">
  868.  
  869. <?php
  870. // $cp_edition = get_option('cp_edition');
  871. $cp_version = get_option('cp_version');
  872. ?>
  873. <div class="stats-info">
  874. <ul>
  875. <li><?php _e('Total Live Ads', 'appthemes')?>: <a href="edit.php?post_status=publish&post_type=<?php echo APP_POST_TYPE ?>"><strong><?php echo $ad_count_live; ?></strong></a></li>
  876. <li><?php _e('Total Pending Ads', 'appthemes')?>: <a href="edit.php?post_status=pending&post_type=<?php echo APP_POST_TYPE ?>"><strong><?php echo $ad_count_pending; ?></strong></a></li>
  877. <li><?php _e('Total Users', 'appthemes')?>: <a href="users.php?orderby=id&order=desc"><strong><?php echo number_format_i18n( $countusers['total_users'] ); ?></strong></a></li>
  878. <li><?php _e('Total Revenue', 'appthemes')?>: <strong><?php echo cp_pos_price( number_format( $ad_rev_total, 2 ) ); ?></strong></li>
  879. <li><?php _e('Product Support', 'appthemes')?>: <a href="http://forums.appthemes.com/" target="_blank"><?php _e('Forum','appthemes')?></a> | <a href="http://docs.appthemes.com/" target="_blank"><?php _e('Documentation','appthemes')?></a></li>
  880. </ul>
  881. </div>
  882.  
  883.  
  884. <div class="stats_overview">
  885. <h3><?php _e('New Registrations', 'appthemes') ?></h3>
  886. <div class="overview_today">
  887. <p class="overview_day"><?php _e('Today', 'appthemes') ?></p>
  888. <p class="overview_count"><?php echo number_format_i18n($customers_today); ?></p>
  889. <p class="overview_type"><em><?php _e('Customers', 'appthemes') ?></em></p>
  890. </div>
  891.  
  892. <div class="overview_previous">
  893. <p class="overview_day"><?php _e('Yesterday', 'appthemes') ?></p>
  894. <p class="overview_count"><?php echo number_format_i18n($customers_yesterday); ?></p>
  895. <p class="overview_type"><em><?php _e('Customers', 'appthemes') ?></em></p>
  896. </div>
  897. </div>
  898.  
  899. </div><!-- /inside -->
  900.  
  901. <div class="clear"></div>
  902.  
  903. </div> <!-- /postbox -->
  904.  
  905.  
  906.  
  907. <div class="postbox">
  908.  
  909. <div class="newspaperico"></div><a target="_new" href="<?php echo $app_rss_feed ?>"><div class="rssico"></div></a>
  910. <h3 class="hndle" id="poststuff"><span><?php _e('Latest News', 'appthemes') ?></span></h3>
  911.  
  912. <div class="inside" id="boxy">
  913.  
  914. <?php appthemes_dashboard_appthemes(); ?>
  915.  
  916. </div> <!-- /inside -->
  917.  
  918. </div> <!-- /postbox -->
  919.  
  920.  
  921. </div> <!-- /dash-wrap -->
  922.  
  923. </div> <!-- /dash-left -->
  924.  
  925.  
  926.  
  927. <div class="dash-right metabox-holder">
  928.  
  929. <div class="dash-wrap">
  930.  
  931. <div class="postbox">
  932.  
  933. <div class="statsico"></div>
  934. <h3 class="hndle" id="poststuff"><span><?php _e('Stats - Last 30 Days', 'appthemes') ?></span></h3>
  935.  
  936. <div class="inside" id="boxy">
  937.  
  938. <?php cp_dashboard_charts(); ?>
  939.  
  940. </div> <!-- /inside -->
  941.  
  942. </div> <!-- /postbox -->
  943.  
  944.  
  945.  
  946. <div class="postbox">
  947.  
  948. <div class="twitterico"></div><a target="_new" href="<?php echo $app_twitter_rss_feed ?>"><div class="rssico"></div></a>
  949. <h3 class="hndle" id="poststuff"><span><?php _e('Latest Tweets', 'appthemes') ?></span></h3>
  950.  
  951. <div class="inside" id="boxy">
  952.  
  953. <?php appthemes_dashboard_twitter(); ?>
  954.  
  955. </div> <!-- /inside -->
  956.  
  957. </div> <!-- /postbox -->
  958.  
  959.  
  960.  
  961. <div class="postbox">
  962.  
  963. <div class="forumico"></div><a target="_new" href="<?php echo $app_forum_rss_feed ?>"><div class="rssico"></div></a>
  964. <h3 class="hndle" id="poststuff"><span><?php _e('Support Forum', 'appthemes') ?></span></h3>
  965.  
  966. <div class="inside" id="boxy">
  967.  
  968. <?php appthemes_dashboard_forum(); ?>
  969.  
  970. </div> <!-- /inside -->
  971.  
  972. </div> <!-- /postbox -->
  973.  
  974.  
  975. </div> <!-- /dash-wrap -->
  976.  
  977. </div> <!-- /dash-right -->
  978.  
  979. </div> <!-- /wrap -->
  980.  
  981. <?php
  982. }
  983.  
  984.  
  985. function cp_settings() {
  986. global $options_settings;
  987.  
  988. cp_update_options($options_settings);
  989. ?>
  990. <script type="text/javascript">
  991. /* upload logo and images */
  992. //<![CDATA[
  993. jQuery(document).ready(function() {
  994. jQuery('.upload_button').click(function() {
  995. formfield = jQuery(this).attr('rel');
  996. tb_show('', 'media-upload.php?type=image&amp;post_id=0&amp;TB_iframe=true');
  997. return false;
  998. });
  999.  
  1000. /* send the uploaded image url to the field */
  1001. window.send_to_editor = function(html) {
  1002. imgurl = jQuery('img',html).attr('src'); // get the image url
  1003. imgoutput = '<img src="' + imgurl + '" />'; //get the html to output for the image preview
  1004. jQuery('#' + formfield).val(imgurl);
  1005. jQuery('#' + formfield).siblings('.upload_image_preview').slideDown().html(imgoutput);
  1006. tb_remove();
  1007. }
  1008. });
  1009. //]]>
  1010. </script>
  1011.  
  1012. <div class="wrap">
  1013.  
  1014. <div class="icon32" id="icon-tools"><br/></div>
  1015. <h2><?php _e('General Settings','appthemes') ?></h2>
  1016.  
  1017. <?php cp_admin_info_box(); ?>
  1018.  
  1019. <form method="post" id="mainform" action="">
  1020.  
  1021. <p class="submit btop"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1022.  
  1023. <?php cp_admin_fields($options_settings); ?>
  1024.  
  1025. <p class="submit bbot"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1026.  
  1027. <input name="submitted" type="hidden" value="yes" />
  1028. <input name="setTabIndex" type="hidden" value="0" id="setTabIndex" />
  1029.  
  1030. </form>
  1031.  
  1032. </div><!-- /wrap -->
  1033.  
  1034. <?php
  1035.  
  1036. }
  1037.  
  1038.  
  1039. function cp_emails() {
  1040. global $options_emails;
  1041.  
  1042. cp_update_options($options_emails);
  1043. ?>
  1044.  
  1045. <div class="wrap">
  1046.  
  1047. <div class="icon32" id="icon-tools"><br/></div>
  1048. <h2><?php _e('Email Settings','appthemes') ?></h2>
  1049.  
  1050. <?php cp_admin_info_box(); ?>
  1051.  
  1052. <form method="post" id="mainform" action="">
  1053.  
  1054. <p class="submit btop"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1055.  
  1056. <?php cp_admin_fields($options_emails); ?>
  1057.  
  1058. <p class="submit bbot"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1059.  
  1060. <input name="submitted" type="hidden" value="yes" />
  1061. <input name="setTabIndex" type="hidden" value="0" id="setTabIndex" />
  1062.  
  1063. </form>
  1064.  
  1065. </div><!-- /wrap -->
  1066.  
  1067. <?php
  1068.  
  1069. }
  1070.  
  1071.  
  1072.  
  1073. function cp_pricing() {
  1074. global $options_pricing;
  1075.  
  1076. cp_update_options($options_pricing);
  1077. ?>
  1078.  
  1079. <script type="text/javascript">
  1080. jQuery(function($) {
  1081.  
  1082. // show/hide for the pricing tab
  1083. var
  1084. $select = $('select#cp_price_scheme'),
  1085. old_val = $select.val();
  1086.  
  1087. $('tr#cp_price_per_cat_row').hide();
  1088. $('tr#cp_percent_per_ad_row').hide();
  1089.  
  1090. if (old_val == 'category') {
  1091. $('tr#cp_price_per_cat_row').show();
  1092. } else if (old_val == 'percentage') {
  1093. $('tr#cp_percent_per_ad_row').show();
  1094. }
  1095.  
  1096. $select.change(function() {
  1097. var new_val = $(this).val();
  1098.  
  1099. if (new_val == 'category') {
  1100. $('tr#cp_price_per_cat_row').fadeIn('fast');
  1101. $('tr#cp_percent_per_ad_row').hide();
  1102. } else if (new_val == 'percentage') {
  1103. $('tr#cp_percent_per_ad_row').fadeIn('fast');
  1104. $('tr#cp_price_per_cat_row').hide();
  1105.  
  1106. } else {
  1107. $('tr#cp_price_per_cat_row').hide();
  1108. $('tr#cp_percent_per_ad_row').hide();
  1109. }
  1110.  
  1111. old_val = new_val;
  1112. });
  1113.  
  1114.  
  1115.  
  1116. // show/hide for the membership tab
  1117. var
  1118. $select2 = $('select#cp_required_membership_type'),
  1119. old_val2 = $select2.val();
  1120.  
  1121. $('tr#cp_required_per_cat_row').hide();
  1122.  
  1123. if (old_val2 == 'category') {
  1124. $('tr#cp_required_per_cat_row').show();
  1125. }
  1126.  
  1127. $select2.change(function() {
  1128. var new_val2 = $(this).val();
  1129.  
  1130. if (new_val2 == 'category') {
  1131. $('tr#cp_required_per_cat_row').fadeIn('fast');
  1132. } else {
  1133. $('tr#cp_required_per_cat_row').hide();
  1134. }
  1135.  
  1136. old_val2 = new_val2;
  1137. });
  1138.  
  1139.  
  1140. });
  1141. </script>
  1142.  
  1143. <div class="wrap">
  1144.  
  1145. <div class="icon32" id="icon-options-general"><br/></div>
  1146. <h2><?php _e('Pricing Options','appthemes') ?></h2>
  1147.  
  1148. <?php cp_admin_info_box(); ?>
  1149.  
  1150. <form method="post" id="mainform" action="">
  1151.  
  1152. <p class="submit btop"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1153.  
  1154. <?php cp_admin_fields($options_pricing); ?>
  1155.  
  1156. <p class="submit bbot"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1157.  
  1158. <input name="submitted" type="hidden" value="yes" />
  1159. <input name="setTabIndex" type="hidden" value="0" id="setTabIndex" />
  1160.  
  1161. </form>
  1162.  
  1163. </div><!-- /wrap -->
  1164.  
  1165. <?php
  1166. }
  1167.  
  1168.  
  1169.  
  1170. // show the ad packages admin page
  1171. function cp_ad_packs() {
  1172. global $app_abbr, $wpdb, $current_user;
  1173.  
  1174. $current_user = wp_get_current_user();
  1175.  
  1176. // check to prevent php "notice: undefined index" msg
  1177. if(isset($_GET['action'])) $theswitch = $_GET['action']; else $theswitch ='';
  1178. ?>
  1179.  
  1180. <script type="text/javascript">
  1181. /* <![CDATA[ */
  1182. /* initialize the form validation */
  1183. jQuery(document).ready(function($) {
  1184. $("#mainform").validate({errorClass: "invalid"});
  1185. });
  1186. /* ]]> */
  1187. </script>
  1188.  
  1189. <?php
  1190. if(isset($_GET['type']) && $_GET['type'] == 'membership')
  1191. $options_new_pack = $GLOBALS['options_new_membership_pack'];
  1192. else
  1193. $options_new_pack = $GLOBALS['options_new_ad_pack'];
  1194.  
  1195. switch ( $theswitch ) {
  1196.  
  1197. case 'addpack':
  1198. ?>
  1199.  
  1200. <div class="wrap">
  1201. <div class="icon32" id="icon-themes"><br/></div>
  1202. <h2><?php if($_GET['type'] == 'membership') _e('New Membership Pack','appthemes'); else _e('New Ad Pack','appthemes'); ?></h2>
  1203.  
  1204. <?php cp_admin_info_box(); ?>
  1205.  
  1206. <?php
  1207. // check and make sure the form was submitted
  1208. if ( isset($_POST['submitted']) ) {
  1209.  
  1210. //setup optional variables for the package
  1211. if(isset($_POST['pack_satisfies_required'])) $post_pack_satisfies_required = $_POST['pack_satisfies_required']; else $post_pack_satisfies_required = '';
  1212. if(isset($_POST['pack_type'])) $post_pack_type = $post_pack_satisfies_required.$_POST['pack_type']; else $post_pack_type = '';
  1213. if(isset($_POST['pack_membership_price'])) $post_pack_membership_price = $_POST['pack_membership_price']; else $post_pack_membership_price = '';
  1214.  
  1215. $values = array(
  1216. "pack_name" => appthemes_clean($_POST['pack_name']),
  1217. "pack_desc" => appthemes_clean($_POST['pack_desc']),
  1218. "pack_price" => appthemes_clean_price($_POST['pack_price'], 'float'),
  1219. "pack_duration" => appthemes_clean($_POST['pack_duration']),
  1220. "pack_status" => appthemes_clean($_POST['pack_status']),
  1221. "pack_type" => appthemes_clean($post_pack_type),
  1222. "pack_membership_price" => appthemes_clean_price($_POST['pack_membership_price'], 'float'),
  1223. "pack_owner" => appthemes_clean($_POST['pack_owner']),
  1224. "pack_modified" => gmdate('Y-m-d H:i:s'),
  1225. );
  1226.  
  1227. $results = $wpdb->insert( $wpdb->cp_ad_packs, $values);
  1228.  
  1229.  
  1230. if ($results !== false) :
  1231. ?>
  1232.  
  1233. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Creating your ad package.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1234. <meta http-equiv="refresh" content="0; URL=?page=packages">
  1235.  
  1236. <?php
  1237. endif;
  1238.  
  1239. } else {
  1240. ?>
  1241.  
  1242. <form method="post" id="mainform" action="">
  1243.  
  1244. <?php cp_admin_fields($options_new_pack) ?>
  1245.  
  1246. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Create New Ad Package','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1247. <input name="cancel" type="button" onClick="location.href='?page=packages'" value="<?php _e('Cancel','appthemes') ?>" /></p>
  1248. <input name="submitted" type="hidden" value="yes" />
  1249. <input name="pack_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1250.  
  1251. </form>
  1252.  
  1253. <?php
  1254. }
  1255. ?>
  1256.  
  1257. </div><!-- end wrap -->
  1258.  
  1259. <?php
  1260. break;
  1261.  
  1262. case 'editpack':
  1263. ?>
  1264.  
  1265. <div class="wrap">
  1266. <div class="icon32" id="icon-themes"><br/></div>
  1267. <h2><?php _e('Edit Ad Package','appthemes') ?></h2>
  1268.  
  1269. <?php cp_admin_info_box(); ?>
  1270.  
  1271. <?php
  1272. if ( isset($_POST['submitted']) && $_POST['submitted'] == 'yes' ) {
  1273.  
  1274. $values = array(
  1275. "pack_name" => appthemes_clean($_POST['pack_name']),
  1276. "pack_desc" => appthemes_clean($_POST['pack_desc']),
  1277. "pack_price" => appthemes_clean_price($_POST['pack_price'], 'float'),
  1278. "pack_duration" => appthemes_clean($_POST['pack_duration']),
  1279. "pack_status" => appthemes_clean($_POST['pack_status']),
  1280. "pack_type" => appthemes_clean($_POST['pack_satisfies_required'].$_POST['pack_type']),
  1281. "pack_membership_price" => appthemes_clean_price($_POST['pack_membership_price'], 'float'),
  1282. "pack_owner" => appthemes_clean($_POST['pack_owner']),
  1283. "pack_modified" => gmdate('Y-m-d H:i:s'),
  1284. );
  1285.  
  1286. $where = array(
  1287. "pack_id" => $_GET['id']
  1288. );
  1289.  
  1290. $wpdb->update( $wpdb->cp_ad_packs, $values, $where);
  1291.  
  1292. ?>
  1293.  
  1294. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Saving your changes.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1295. <meta http-equiv="refresh" content="0; URL=?page=packages">
  1296.  
  1297. <?php
  1298. } else {
  1299. ?>
  1300.  
  1301.  
  1302. <form method="post" id="mainform" action="">
  1303.  
  1304. <?php
  1305. cp_admin_db_fields($options_new_pack, 'cp_ad_packs', 'pack_id');
  1306. ?>
  1307.  
  1308. <p class="submit">
  1309. <input class="btn button-primary" name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1310. <input name="cancel" type="button" onClick="location.href='?page=packages'" value="<?php _e('Cancel','appthemes') ?>" />
  1311. <input name="submitted" type="hidden" value="yes" />
  1312. <input name="pack_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1313. </p>
  1314.  
  1315. </form>
  1316.  
  1317. <?php } ?>
  1318.  
  1319. </div><!-- end wrap -->
  1320.  
  1321. <?php
  1322. break;
  1323.  
  1324. case 'delete':
  1325.  
  1326. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->cp_ad_packs WHERE pack_id = %s", $_GET['id'] ) );
  1327. ?>
  1328.  
  1329. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting ad package.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1330. <meta http-equiv="refresh" content="0; URL=?page=packages">
  1331.  
  1332. <?php
  1333. break;
  1334.  
  1335. default:
  1336.  
  1337. $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->cp_ad_packs ORDER BY pack_id desc" ) );
  1338.  
  1339. ?>
  1340.  
  1341. <div class="wrap">
  1342. <div class="icon32" id="icon-themes"><br/></div>
  1343. <h2><?php _e('Ad Packs','appthemes') ?>&nbsp;<a class="button add-new-h2" href="?page=packages&amp;action=addpack&amp;type=ad"><?php _e('Add New','appthemes') ?></a></h2>
  1344.  
  1345. <?php cp_admin_info_box(); ?>
  1346.  
  1347. <?php if ( get_option( $app_abbr.'_price_scheme') != 'single' ) { ?>
  1348. <div class="error"><p><?php printf(__('Ad Packs are disabled. Change the <a href="%1$s">pricing model</a> to enable Ad Packs.', 'appthemes'), 'admin.php?page=pricing#tab1' ); ?></p></div>
  1349. <?php } ?>
  1350.  
  1351. <p class="admin-msg"><?php _e('Ad Packs allow you to create bundled listing options for your customers to choose from. For example, instead of only offering a set price for xx days (30 days for $5), you could also offer discounts for longer terms (60 days for $7). These only work if you are selling ads and using the "Fixed Price Per Ad" price model.','appthemes') ?></p>
  1352.  
  1353. <table id="tblspacer" class="widefat fixed">
  1354.  
  1355. <thead>
  1356. <tr>
  1357. <th scope="col" style="width:35px;">&nbsp;</th>
  1358. <th scope="col"><?php _e('Name','appthemes') ?></th>
  1359. <th scope="col"><?php _e('Description','appthemes') ?></th>
  1360. <th scope="col"><?php _e('Price Per Ad','appthemes') ?></th>
  1361. <th scope="col"><?php _e('Duration','appthemes') ?></th>
  1362. <th scope="col" style="width:150px;"><?php _e('Modified','appthemes') ?></th>
  1363. <th scope="col" style="width:75px;"><?php _e('Status','appthemes') ?></th>
  1364. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  1365. </tr>
  1366. </thead>
  1367.  
  1368. <?php
  1369. if ( $results ) {
  1370. $rowclass = '';
  1371. $i=1;
  1372. ?>
  1373.  
  1374. <tbody id="list">
  1375.  
  1376. <?php
  1377. foreach ( $results as $result ) {
  1378. if ( $result->pack_status == 'active' || $result->pack_status == 'inactive' ) :
  1379. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  1380. ?>
  1381.  
  1382. <tr class="<?php echo $rowclass ?>">
  1383. <td style="padding-left:10px;"><?php echo $i++; ?>.</td>
  1384. <td><a href="?page=packages&amp;action=editpack&amp;type=ad&amp;id=<?php echo $result->pack_id ?>"><strong><?php echo stripslashes($result->pack_name); ?></strong></a></td>
  1385. <td><?php echo $result->pack_desc ?></td>
  1386. <td><?php echo cp_pos_price( $result->pack_price ) ?></td>
  1387. <td><?php echo $result->pack_duration ?>&nbsp;<?php _e('days','appthemes') ?></td>
  1388. <td><?php echo mysql2date( get_option('date_format') .' '. get_option('time_format'), $result->pack_modified ) ?> <?php _e('by','appthemes') ?> <?php echo $result->pack_owner; ?></td>
  1389. <td><?php echo ucwords( $result->pack_status ) ?></td>
  1390. <td style="text-align:center">
  1391. <a href="?page=packages&amp;action=editpack&amp;type=ad&amp;id=<?php echo $result->pack_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/edit.png" alt="<?php echo _e('Edit ad package','appthemes') ?>" title="<?php echo _e('Edit ad package','appthemes') ?>" /></a>&nbsp;&nbsp;&nbsp;
  1392. <a onclick="return confirmBeforeDelete();" href="?page=packages&amp;action=delete&amp;id=<?php echo $result->pack_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/cross.png" alt="<?php echo _e('Delete ad package','appthemes') ?>" title="<?php echo _e('Delete ad package','appthemes') ?>" /></a>
  1393. </td>
  1394. </tr>
  1395.  
  1396. <?php
  1397. endif; //end if('active' || 'inactive')
  1398.  
  1399. } // end for each
  1400. unset($i);
  1401. ?>
  1402.  
  1403. </tbody>
  1404.  
  1405. <?php
  1406.  
  1407. } else {
  1408.  
  1409. ?>
  1410.  
  1411. <tr>
  1412. <td colspan="7"><?php _e('No ad packs found.','appthemes') ?></td>
  1413. </tr>
  1414.  
  1415. <?php
  1416. } // end $results
  1417. ?>
  1418.  
  1419. </table>
  1420.  
  1421.  
  1422. </div><!-- end wrap for ad packs -->
  1423.  
  1424. <div id="membership-packs" class="wrap">
  1425. <div class="icon32" id="icon-themes"><br/></div>
  1426. <h2><?php _e('Membership Packs','appthemes') ?>&nbsp;<a class="button add-new-h2" href="?page=packages&amp;action=addpack&amp;type=membership"><?php _e('Add New','appthemes') ?></a></h2>
  1427.  
  1428. <?php cp_admin_info_box(); ?>
  1429.  
  1430. <p class="admin-msg"><?php printf(__('Membership Packs allow you to setup subscription-based pricing packages. This enables your customers to post unlimited ads for a set period of time or until the membership becomes inactive. These memberships affect pricing regardless of the ad packs or pricing model you have set as long as you have the <a href="%1$s">enable membership packs</a> option set to yes.','appthemes'), 'admin.php?page=pricing#tab2'); ?></p>
  1431.  
  1432. <table id="tblspacer" class="widefat fixed">
  1433.  
  1434. <thead>
  1435. <tr>
  1436. <th scope="col" style="width:35px;">&nbsp;</th>
  1437. <th scope="col"><?php _e('Name','appthemes') ?></th>
  1438. <th scope="col"><?php _e('Description','appthemes') ?></th>
  1439. <th scope="col"><?php _e('Price Modifier','appthemes') ?></th>
  1440. <th scope="col"><?php _e('Terms','appthemes') ?></th>
  1441. <th scope="col" style="width:150px;"><?php _e('Modified','appthemes') ?></th>
  1442. <th scope="col" style="width:75px;"><?php _e('Status','appthemes') ?></th>
  1443. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  1444. </tr>
  1445. </thead>
  1446.  
  1447. <?php
  1448. if ( $results ) {
  1449. $rowclass = '';
  1450. $i=1;
  1451. ?>
  1452.  
  1453. <tbody id="list">
  1454.  
  1455. <?php
  1456. foreach ( $results as $result ) {
  1457. if ( $result->pack_status == 'active_membership' || $result->pack_status == 'inactive_membership' ) :
  1458. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  1459. ?>
  1460.  
  1461. <tr class="<?php echo $rowclass ?>">
  1462. <td style="padding-left:10px;"><?php echo $i++ ?>.</td>
  1463. <td><a href="?page=packages&amp;action=editpack&amp;type=membership&amp;id=<?php echo $result->pack_id; ?>"><strong><?php echo stripslashes($result->pack_name); ?></strong></a></td>
  1464. <td><?php echo $result->pack_desc; ?></td>
  1465. <td>
  1466. <?php switch ($result->pack_type) {
  1467. case 'percentage':
  1468. echo preg_replace('/.00$/', '', $result->pack_price).'% '.__('of price','appthemes'); //remove decimal when decimal is .00
  1469. break;
  1470. case 'discount':
  1471. echo cp_pos_price($result->pack_price).__('\'s less per ad','appthemes');
  1472. break;
  1473. case 'required_static':
  1474. if ( (float)$result->pack_price == 0 ) echo __('Free','appthemes');
  1475. else echo cp_pos_price( $result->pack_price ).__(' per ad','appthemes');
  1476. echo ' ('.__('required to post','appthemes').')';
  1477. break;
  1478. case 'required_discount':
  1479. echo cp_pos_price( $result->pack_price ).__('\'s less per ad','appthemes');
  1480. echo ' ('.__('required to post','appthemes').')';
  1481. break;
  1482. case 'required_percentage':
  1483. echo preg_replace( '/.00$/', '', $result->pack_price ).'% '.__('of price','appthemes'); //remove decimal when decimal is .00
  1484. echo ' ('.__('required to post','appthemes').')';
  1485. break;
  1486. default: //likely 'static'
  1487. if ( (float)$result->pack_price == 0 ) echo __('Free','appthemes');
  1488. else echo cp_pos_price( $result->pack_price ).__(' per ad','appthemes');
  1489. }
  1490. ?>
  1491. </td>
  1492. <td><?php echo cp_pos_price( $result->pack_membership_price ).' / '.$result->pack_duration.' '.__('days','appthemes'); ?></td>
  1493. <td><?php echo mysql2date( get_option('date_format') .' '. get_option('time_format'), $result->pack_modified ) ?> <?php _e('by','appthemes') ?> <?php echo $result->pack_owner; ?></td>
  1494. <td><?php echo ucwords(preg_replace('/\_(.*)/', '', $result->pack_status)) ?></td>
  1495. <td style="text-align:center">
  1496. <a href="?page=packages&amp;action=editpack&amp;type=membership&amp;id=<?php echo $result->pack_id ?>"><img src="<?php echo bloginfo('template_directory'); ?>/images/edit.png" alt="<?php echo _e('Edit ad package','appthemes'); ?>" title="<?php echo _e('Edit ad package','appthemes') ?>" /></a>&nbsp;&nbsp;&nbsp;
  1497. <a onclick="return confirmBeforeDelete();" href="?page=packages&amp;action=delete&amp;id=<?php echo $result->pack_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/cross.png" alt="<?php echo _e('Delete ad package','appthemes'); ?>" title="<?php echo _e('Delete ad package','appthemes') ?>" /></a>
  1498. </td>
  1499. </tr>
  1500.  
  1501. <?php
  1502. endif; //end if('active_membership' || 'inactive_membership')
  1503.  
  1504. } // end for each
  1505. unset($i);
  1506. ?>
  1507.  
  1508. </tbody>
  1509.  
  1510. <?php
  1511.  
  1512. } else {
  1513.  
  1514. ?>
  1515.  
  1516. <tr>
  1517. <td colspan="7"><?php _e('No ad packs found.','appthemes') ?></td>
  1518. </tr>
  1519.  
  1520. <?php
  1521. } // end $results
  1522. ?>
  1523.  
  1524. </table>
  1525.  
  1526.  
  1527. </div><!-- end wrap for membership packs-->
  1528.  
  1529. <?php
  1530. } // end switch
  1531. ?>
  1532. <script type="text/javascript">
  1533. /* <![CDATA[ */
  1534. function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this ad package?', 'appthemes'); ?>"); }
  1535. /* ]]> */
  1536. </script>
  1537.  
  1538. <?php
  1539.  
  1540. }
  1541.  
  1542.  
  1543. // show the ad packages admin page
  1544. function cp_coupons() {
  1545. global $options_new_coupon, $wpdb, $current_user, $app_version;
  1546.  
  1547. $current_user = wp_get_current_user();
  1548.  
  1549. // check to prevent php "notice: undefined index" msg
  1550. if(isset($_GET['action'])) $theswitch = $_GET['action']; else $theswitch ='';
  1551. ?>
  1552.  
  1553. <script type="text/javascript">
  1554. //<![CDATA[
  1555. /* initialize the datepicker feature */
  1556. jQuery(document).ready(function($) {
  1557. /* initialize the form validation */
  1558. $("#mainform").validate({errorClass: "invalid"});
  1559.  
  1560. $('form#mainform .datepicker').datepicker({
  1561. showOn: 'button',
  1562. dateFormat: 'yy-mm-dd',
  1563. minDate: 0,
  1564. buttonImageOnly: true,
  1565. buttonText: '',
  1566. buttonImage: '../wp-includes/images/blank.gif' // calling the real calendar image in the admin-style.css. need a blank placeholder image b/c of IE.
  1567. });
  1568. });
  1569. //]]>
  1570. </script>
  1571.  
  1572. <?php
  1573. switch ( $theswitch ) {
  1574.  
  1575. case 'addcoupon':
  1576. ?>
  1577.  
  1578. <div class="wrap">
  1579. <div class="icon32" id="icon-edit-pages"><br/></div>
  1580. <h2><?php _e('New Coupon','appthemes') ?></h2>
  1581. <?php
  1582. //if your database is not at least version 3.1, you must upgrade first.
  1583. if ( get_option('cp_version') != $app_version ) {
  1584. echo '<div class="error">' . __('Error: Your ClassiPress database is not updated to match your version of ClassiPress.','appthemes') . '</div>';
  1585. echo __('Product Version', 'appthemes') . ': <strong>' . get_option('cp_version') . '</strong> ';
  1586. if ( get_option('cp_version') != $app_version )
  1587. echo __('(You upgraded to version ') . $app_version . '. <a href="admin.php?page=admin-options.php&upgrade=yes">Click here to finish your upgrade.</a>)';
  1588. die();
  1589. }
  1590. ?>
  1591.  
  1592. <?php cp_admin_info_box(); ?>
  1593.  
  1594. <?php
  1595. // check and make sure the form was submitted
  1596. if ( isset($_POST['submitted']) ) {
  1597.  
  1598. //echo $_POST['coupon_expire_date'] . '<-- expire date';
  1599.  
  1600. // @todo Switch to
  1601. // adding $wpdb->prepare causes the query to be empty for some reason
  1602. $insert = "INSERT INTO $wpdb->cp_coupons" .
  1603. " (coupon_code, coupon_desc, coupon_discount, coupon_discount_type, coupon_start_date, coupon_expire_date, coupon_status, coupon_max_use_count, coupon_owner, coupon_created, coupon_modified) " .
  1604. "VALUES ('" .
  1605. $wpdb->escape(appthemes_clean($_POST['coupon_code'])) . "','" .
  1606. $wpdb->escape(appthemes_clean($_POST['coupon_desc'])) . "','" .
  1607. $wpdb->escape(appthemes_clean($_POST['coupon_discount'])) . "','" .
  1608. $wpdb->escape(appthemes_clean($_POST['coupon_discount_type'])) . "','" .
  1609. $wpdb->escape(appthemes_clean($_POST['coupon_start_date'])) . "','" .
  1610. $wpdb->escape(appthemes_clean($_POST['coupon_expire_date'])) . "','" .
  1611. $wpdb->escape(appthemes_clean($_POST['coupon_status'])) . "','" .
  1612. $wpdb->escape(appthemes_clean($_POST['coupon_max_use_count'])) . "','" .
  1613. $wpdb->escape(appthemes_clean($_POST['coupon_owner'])) . "','" .
  1614. gmdate('Y-m-d H:i:s') . "','" .
  1615. gmdate('Y-m-d H:i:s') .
  1616. "')";
  1617.  
  1618. $results = $wpdb->query( $insert );
  1619.  
  1620.  
  1621. if ( $results ) :
  1622. ?>
  1623.  
  1624. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Creating your coupon.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1625. <meta http-equiv="refresh" content="0; URL=?page=coupons">
  1626.  
  1627. <?php
  1628. endif;
  1629.  
  1630.  
  1631. } else {
  1632. ?>
  1633.  
  1634. <form method="post" id="mainform" action="">
  1635.  
  1636. <?php cp_admin_fields($options_new_coupon) ?>
  1637.  
  1638. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Create New Coupon','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1639. <input name="cancel" type="button" onClick="location.href='?page=coupons'" value="<?php _e('Cancel','appthemes') ?>" /></p>
  1640. <input name="submitted" type="hidden" value="yes" />
  1641. <input name="coupon_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1642.  
  1643. </form>
  1644.  
  1645. <?php
  1646. }
  1647. ?>
  1648.  
  1649. </div><!-- end wrap -->
  1650.  
  1651. <?php
  1652. break;
  1653.  
  1654. case 'editcoupon':
  1655. ?>
  1656.  
  1657. <div class="wrap">
  1658. <div class="icon32" id="icon-themes"><br/></div>
  1659. <h2><?php _e('Edit Coupon','appthemes') ?></h2>
  1660.  
  1661. <?php cp_admin_info_box(); ?>
  1662.  
  1663. <?php
  1664. if ( isset($_POST['submitted']) && $_POST['submitted'] == 'yes' ) {
  1665.  
  1666. // adding $wpdb->prepare causes the query to be empty for some reason
  1667. $update = "UPDATE $wpdb->cp_coupons SET" .
  1668. " coupon_code = '" . $wpdb->escape(appthemes_clean($_POST['coupon_code'])) . "'," .
  1669. " coupon_desc = '" . $wpdb->escape(appthemes_clean($_POST['coupon_desc'])) . "'," .
  1670. " coupon_discount = '" . $wpdb->escape(appthemes_clean($_POST['coupon_discount'])) . "'," .
  1671. " coupon_discount_type = '" . $wpdb->escape(appthemes_clean($_POST['coupon_discount_type'])) . "'," .
  1672. " coupon_start_date = '" . $wpdb->escape(appthemes_clean($_POST['coupon_start_date'])) . "'," .
  1673. " coupon_expire_date = '" . $wpdb->escape(appthemes_clean($_POST['coupon_expire_date'])) . "'," .
  1674. " coupon_status = '" . $wpdb->escape(appthemes_clean($_POST['coupon_status'])) . "'," .
  1675. " coupon_max_use_count = '" . $wpdb->escape(appthemes_clean($_POST['coupon_max_use_count'])) . "'," .
  1676. " coupon_owner = '" . $wpdb->escape(appthemes_clphp
  1677. switch ean($_POST['coupon_owner'])) . "'," .
  1678. " coupon_modified = '" . gmdate('Y-m-d H:i:s') . "'" .
  1679. " WHERE coupon_id ='" . $wpdb->escape($_GET['id']) ."'";
  1680.  
  1681. $results = $wpdb->get_row( $update );
  1682. ?>
  1683.  
  1684. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Saving your changes.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1685. <meta http-equiv="refresh" content="0; URL=?page=coupons">
  1686.  
  1687. <?php
  1688. } else {
  1689. ?>
  1690.  
  1691.  
  1692. <form method="post" id="mainform" action="">
  1693.  
  1694. <?php cp_admin_db_fields($options_new_coupon, 'cp_coupons', 'coupon_id') ?>
  1695.  
  1696. <p class="submit">
  1697. <input class="btn button-primary" name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1698. <input name="cancel" type="button" onClick="location.href='?page=coupons'" value="<?php _e('Cancel','appthemes') ?>" />
  1699. <input name="submitted" type="hidden" value="yes" />
  1700. <input name="coupon_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1701. </p>
  1702.  
  1703. </form>
  1704.  
  1705. <?php } ?>
  1706.  
  1707. </div><!-- end wrap -->
  1708.  
  1709. <?php
  1710. break;
  1711.  
  1712. case 'delete':
  1713.  
  1714. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->cp_coupons WHERE coupon_id = %s", $_GET['id'] ) );
  1715. ?>
  1716.  
  1717. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting coupon.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1718. <meta http-equiv="refresh" content="0; URL=?page=coupons">
  1719.  
  1720. <?php
  1721. break;
  1722.  
  1723. default:
  1724.  
  1725. $results = cp_get_coupons();
  1726.  
  1727. ?>
  1728.  
  1729. <div class="wrap">
  1730. <div class="icon32" id="icon-edit-pages"><br/></div>
  1731. <h2><?php _e('Coupons','appthemes') ?>&nbsp;<a class="button add-new-h2" href="?page=coupons&amp;action=addcoupon"><?php _e('Add New','appthemes') ?></a></h2>
  1732.  
  1733. <?php cp_admin_info_box(); ?>
  1734.  
  1735.  
  1736. <p class="admin-msg"><?php _e('Create coupons to offer special discounts to your customers.','appthemes') ?></p>
  1737.  
  1738. <table id="tblspacer" class="widefat fixed">
  1739.  
  1740. <thead>
  1741. <tr>
  1742. <th scope="col" style="width:35px;">&nbsp;</th>
  1743. <th scope="col"><?php _e('Code','appthemes') ?></th>
  1744. <th scope="col"><?php _e('Description','appthemes') ?></th>
  1745. <th scope="col"><?php _e('Discount','appthemes') ?></th>
  1746. <th scope="col"><?php _e('Usage','appthemes') ?></th>
  1747. <th scope="col"><?php _e('Valid','appthemes') ?></th>
  1748. <th scope="col"><?php _e('Expires','appthemes') ?></th>
  1749. <th scope="col" style="width:150px;"><?php _e('Modified','appthemes') ?></th>
  1750. <th scope="col" style="width:75px;"><?php _e('Status','appthemes') ?></th>
  1751. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  1752. </tr>
  1753. </thead>
  1754.  
  1755. <?php
  1756. if ( $results ) {
  1757. $rowclass = '';
  1758. $i=1;
  1759. ?>
  1760.  
  1761. <tbody id="list">
  1762.  
  1763. <?php
  1764. foreach ( $results as $result ) {
  1765.  
  1766. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  1767. ?>
  1768.  
  1769. <tr class="<?php echo $rowclass ?>">
  1770. <td style="padding-left:10px;"><?php echo $i ?>.</td>
  1771. <td><a href="?page=coupons&amp;action=editcoupon&amp;id=<?php echo $result->coupon_id ?>"><strong><?php echo $result->coupon_code ?></strong></a></td>
  1772. <td><?php echo $result->coupon_desc ?></td>
  1773. <td><?php if (($result->coupon_discount_type) == '%') echo number_format($result->coupon_discount,0) . '%'; else echo cp_pos_price($result->coupon_discount); ?></td>
  1774. <td><?php echo $result->coupon_use_count ?><?php if (($result->coupon_max_use_count) <> 0) echo '/' . $result->coupon_max_use_count ?></td>
  1775. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->coupon_start_date) ?></td>
  1776. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->coupon_expire_date) ?></td>
  1777. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->coupon_modified) ?> <br /><?php _e('by','appthemes') ?> <?php echo $result->coupon_owner; ?></td>
  1778. <td><?php echo ucfirst($result->coupon_status) ?></td>
  1779. <td style="text-align:center">
  1780. <a href="?page=coupons&amp;action=editcoupon&amp;id=<?php echo $result->coupon_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/edit.png" alt="<?php echo _e('Edit coupon','appthemes') ?>" title="<?php echo _e('Edit coupon','appthemes') ?>" /></a>&nbsp;&nbsp;&nbsp;
  1781. <a onclick="return confirmBeforeDelete();" href="?page=coupons&amp;action=delete&amp;id=<?php echo $result->coupon_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/cross.png" alt="<?php echo _e('Delete coupon','appthemes') ?>" title="<?php echo _e('Delete coupon','appthemes') ?>" /></a>
  1782. </td>
  1783. </tr>
  1784.  
  1785. <?php
  1786.  
  1787. $i++;
  1788.  
  1789. } // end for each
  1790. ?>
  1791.  
  1792. </tbody>
  1793.  
  1794. <?php
  1795.  
  1796. } else {
  1797.  
  1798. ?>
  1799.  
  1800. <tr>
  1801. <td>&nbsp;</td><td colspan="8"><?php _e('No coupons found.','appthemes') ?></td>
  1802. </tr>
  1803.  
  1804. <?php
  1805. } // end $results
  1806. ?>
  1807.  
  1808. </table>
  1809.  
  1810.  
  1811. </div><!-- end wrap -->
  1812.  
  1813. <?php
  1814. } // end switch
  1815. ?>
  1816. <script type="text/javascript">
  1817. /* <![CDATA[ */
  1818. function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this coupon?', 'appthemes'); ?>"); }
  1819. /* ]]> */
  1820. </script>
  1821.  
  1822. <?php
  1823.  
  1824. }
  1825.  
  1826.  
  1827.  
  1828. function cp_gateways() {
  1829. global $options_gateways;
  1830.  
  1831. cp_update_options($options_gateways);
  1832. ?>
  1833.  
  1834. <div class="wrap">
  1835.  
  1836. <div class="icon32" id="icon-options-general"><br/></div>
  1837. <h2><?php _e('Payment Gateways','appthemes') ?></h2>
  1838.  
  1839. <?php cp_admin_info_box(); ?>
  1840.  
  1841. <form method="post" id="mainform" action="">
  1842.  
  1843. <p class="submit btop"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1844.  
  1845. <?php cp_admin_fields($options_gateways); ?>
  1846.  
  1847. <p class="submit bbot"><input name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" /></p>
  1848.  
  1849. <input name="submitted" type="hidden" value="yes" />
  1850. <input name="setTabIndex" type="hidden" value="0" id="setTabIndex" />
  1851.  
  1852. </form>
  1853.  
  1854. </div>
  1855.  
  1856. <?php
  1857. }
  1858.  
  1859.  
  1860. function cp_form_layouts() {
  1861. global $options_new_form, $wpdb, $current_user;
  1862.  
  1863. $current_user = wp_get_current_user();
  1864.  
  1865. // check to prevent php "notice: undefined index" msg when php strict warnings is on
  1866. if ( isset($_GET['action']) ) $theswitch = $_GET['action']; else $theswitch ='';
  1867. ?>
  1868.  
  1869. <script type="text/javascript">
  1870. /* <![CDATA[ */
  1871. /* initialize the form validation */
  1872. jQuery(document).ready(function($) {
  1873. $("#mainform").validate({errorClass: "invalid"});
  1874. });
  1875. /* ]]> */
  1876. </script>
  1877.  
  1878. <?php
  1879. switch ( $theswitch ) {
  1880.  
  1881. case 'addform':
  1882. ?>
  1883.  
  1884. <div class="wrap">
  1885. <div class="icon32" id="icon-themes"><br/></div>
  1886. <h2><?php _e('New Form Layout','appthemes') ?></h2>
  1887.  
  1888. <?php cp_admin_info_box(); ?>
  1889.  
  1890. <?php
  1891. // check and make sure the form was submitted and the hidden fcheck id matches the cookie fcheck id
  1892. if ( isset($_POST['submitted']) ) {
  1893.  
  1894. if ( !isset($_POST['post_category']) )
  1895. wp_die( '<p style="color:red;">' .__("Error: Please select at least one category. <a href='#' onclick='history.go(-1);return false;'>Go back</a>",'appthemes') .'</p>' );
  1896.  
  1897. // @todo Change to Insert
  1898. $insert = $wpdb->prepare( "INSERT INTO $wpdb->cp_ad_forms" .
  1899. " (form_name, form_label, form_desc, form_cats, form_status, form_owner, form_created) " .
  1900. "VALUES ( %s, %s, %s, %s, %s, %s, %s)",
  1901. appthemes_clean(cp_make_custom_name($_POST['form_label'])),
  1902. appthemes_clean($_POST['form_label']),
  1903. appthemes_clean($_POST['form_desc']),
  1904. serialize($_POST['post_category']),
  1905. appthemes_clean($_POST['form_status']),
  1906. appthemes_clean($_POST['form_owner']),
  1907. gmdate('Y-m-d H:i:s')
  1908. );
  1909.  
  1910. $results = $wpdb->query( $insert );
  1911.  
  1912.  
  1913. if ( $results ) {
  1914. ?>
  1915.  
  1916. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Creating your form.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1917. <meta http-equiv="refresh" content="0; URL=?page=layouts">
  1918.  
  1919. <?php
  1920. } // end $results
  1921.  
  1922. } else {
  1923. ?>
  1924.  
  1925. <form method="post" id="mainform" action="">
  1926.  
  1927. <?php echo cp_admin_fields($options_new_form); ?>
  1928.  
  1929. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Create New Form','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1930. <input name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel','appthemes') ?>" /></p>
  1931. <input name="submitted" type="hidden" value="yes" />
  1932. <input name="form_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1933.  
  1934. </form>
  1935.  
  1936. <?php
  1937. } // end isset $_POST
  1938. ?>
  1939.  
  1940. </div><!-- end wrap -->
  1941.  
  1942. <?php
  1943. break;
  1944.  
  1945.  
  1946. case 'editform':
  1947. ?>
  1948.  
  1949. <div class="wrap">
  1950. <div class="icon32" id="icon-themes"><br/></div>
  1951. <h2><?php _e('Edit Form Properties','appthemes') ?></h2>
  1952.  
  1953. <?php
  1954. if ( isset($_POST['submitted']) && $_POST['submitted'] == 'yes' ) {
  1955.  
  1956. if ( !isset($_POST['post_category']) )
  1957. wp_die( '<p style="color:red;">' .__("Error: Please select at least one category. <a href='#' onclick='history.go(-1);return false;'>Go back</a>",'appthemes') .'</p>' );
  1958.  
  1959.  
  1960. // @todo Change to Update
  1961. $update = $wpdb->prepare( "UPDATE $wpdb->cp_ad_forms SET" .
  1962. " form_label = %s," .
  1963. " form_desc = %s," .
  1964. " form_cats = %s," .
  1965. " form_status = %s," .
  1966. " form_owner = %s," .
  1967. " form_modified = %s" .
  1968. " WHERE id = %s",
  1969. appthemes_clean($_POST['form_label']),
  1970. appthemes_clean($_POST['form_desc']),
  1971. serialize($_POST['post_category']),
  1972. appthemes_clean($_POST['form_status']),
  1973. $_POST['form_owner'],
  1974. gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ),
  1975. $_GET['id']);
  1976.  
  1977. $results = $wpdb->get_row( $update );
  1978.  
  1979. ?>
  1980.  
  1981. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Saving your changes.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  1982. <meta http-equiv="refresh" content="0; URL=?page=layouts">
  1983.  
  1984. <?php
  1985. } else {
  1986. ?>
  1987.  
  1988. <form method="post" id="mainform" action="">
  1989.  
  1990. <?php echo cp_admin_db_fields($options_new_form, 'cp_ad_forms', 'id'); ?>
  1991.  
  1992. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  1993. <input name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel','appthemes') ?>" /></p>
  1994. <input name="submitted" type="hidden" value="yes" />
  1995. <input name="form_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  1996.  
  1997. </form>
  1998.  
  1999. <?php
  2000. } // end isset $_POST
  2001. ?>
  2002.  
  2003. </div><!-- end wrap -->
  2004.  
  2005. <?php
  2006. break;
  2007.  
  2008.  
  2009. /**
  2010. * Form Builder Page
  2011. * Where fields are added to form layouts
  2012. */
  2013.  
  2014. case 'formbuilder':
  2015. ?>
  2016.  
  2017. <div class="wrap">
  2018. <div class="icon32" id="icon-themes"><br/></div>
  2019. <h2><?php _e('Edit Form Layout','appthemes') ?></h2>
  2020.  
  2021. <?php cp_admin_info_box(); ?>
  2022.  
  2023. <?php
  2024. // add fields to page layout on left side
  2025. if ( isset($_POST['field_id']) ) {
  2026.  
  2027. // take selected checkbox array and loop through ids
  2028. foreach ( $_POST['field_id'] as $value ) {
  2029.  
  2030. // @todo Change to Insert
  2031. $insert = $wpdb->prepare( "INSERT INTO $wpdb->cp_ad_meta" .
  2032. " (form_id, field_id) VALUES ( %s, %s)",
  2033. appthemes_clean($_POST['form_id']),
  2034. appthemes_clean($value)
  2035. );
  2036.  
  2037. $results = $wpdb->query( $insert );
  2038.  
  2039. } // end foreach
  2040.  
  2041. } // end $_POST
  2042.  
  2043.  
  2044.  
  2045. // update form layout positions and required fields on left side.
  2046. if ( isset($_POST['formlayout']) ) {
  2047.  
  2048. // loop through the post array and update the required checkbox and field position
  2049. foreach ( $_POST as $key => $value ) :
  2050.  
  2051. // since there's some $_POST values we don't want to process, only give us the
  2052. // numeric ones which means it contains a meta_id and we want to update it
  2053. if ( is_numeric($key) ) {
  2054.  
  2055. // quick hack to prevent php "notice: undefined index:" msg when php strict warnings is on
  2056. if ( !isset($value['field_req']) ) $value['field_req'] = '';
  2057. if ( !isset($value['field_search']) ) $value['field_search'] = '';
  2058.  
  2059. $update = "UPDATE $wpdb->cp_ad_meta SET "
  2060. . "field_req = '" . $wpdb->escape(appthemes_clean($value['field_req'])) . "', "
  2061. . "field_search = '" . $wpdb->escape(appthemes_clean($value['field_search'])) . "' "
  2062. . "WHERE meta_id ='" . $wpdb->escape($key) ."'";
  2063.  
  2064. $wpdb->query( $update );
  2065.  
  2066. } // end if_numeric
  2067.  
  2068. endforeach; // end for each
  2069.  
  2070. echo '<p class="info">'. __('Your changes have been saved.', 'appthemes') .'</p>';
  2071.  
  2072. } // end isset $_POST
  2073.  
  2074.  
  2075. // check to prevent php "notice: undefined index" msg when php strict warnings is on
  2076. if ( isset($_GET['del_id']) ) $theswitch = $_GET['del_id']; else $theswitch ='';
  2077.  
  2078.  
  2079. // Remove items from form layout
  2080. if ( $theswitch ) $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->cp_ad_meta WHERE meta_id = %s", $_GET['del_id'] ) );
  2081.  
  2082.  
  2083. // @todo Change to Update
  2084. //update the forms modified date
  2085. $update = $wpdb->prepare( "UPDATE $wpdb->cp_ad_forms SET" .
  2086. " form_modified = %s WHERE id = %s",
  2087. gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ),
  2088. $_GET['id']
  2089. );
  2090.  
  2091. $results = $wpdb->get_row( $update );
  2092.  
  2093. ?>
  2094.  
  2095.  
  2096. <table>
  2097. <tr style="vertical-align:top;">
  2098. <td style="width:800px;padding:0 20px 0 0;">
  2099.  
  2100.  
  2101. <h3><?php _e('Form Name','appthemes') ?> - <?php echo ucfirst(urldecode($_GET['title'])) ?>&nbsp;&nbsp;&nbsp;&nbsp;<span id="loading"></span></h3>
  2102.  
  2103. <form method="post" id="mainform" action="">
  2104.  
  2105. <table class="widefat">
  2106. <thead>
  2107. <tr>
  2108. <th scope="col" colspan="2"><?php _e('Form Preview','appthemes') ?></th>
  2109. <th scope="col" style="width:75px;text-align:center;" title="<?php _e('Show field in the category refine search sidebar','appthemes') ?>"><?php _e('Advanced Search','appthemes') ?></th>
  2110. <th scope="col" style="width:75px;text-align:center;"><?php _e('Required','appthemes') ?></th>
  2111. <th scope="col" style="width:75px;text-align:center;"><?php _e('Remove','appthemes') ?></th>
  2112. </tr>
  2113. </thead>
  2114.  
  2115.  
  2116.  
  2117. <tbody class="sortable">
  2118.  
  2119. <?php
  2120.  
  2121. // If this is the first time this form is being customized then auto
  2122. // create the core fields and put in cp_meta db table
  2123. echo cp_add_core_fields( $_GET['id'] );
  2124.  
  2125.  
  2126. // Then go back and select all the fields assigned to this
  2127. // table which now includes the added core fields.
  2128. $sql = $wpdb->prepare( "SELECT f.field_label, f.field_name, f.field_type, f.field_values, f.field_perm, m.meta_id, m.field_pos, m.field_search, m.field_req, m.form_id "
  2129. . "FROM $wpdb->cp_ad_fields f "
  2130. . "INNER JOIN $wpdb->cp_ad_meta m "
  2131. . "ON f.field_id = m.field_id "
  2132. . "WHERE m.form_id = %s "
  2133. . "ORDER BY m.field_pos asc",
  2134. $_GET['id']
  2135. );
  2136.  
  2137. $results = $wpdb->get_results( $sql );
  2138.  
  2139. if ( $results ) {
  2140.  
  2141. echo cp_admin_formbuilder( $results );
  2142.  
  2143. } else {
  2144.  
  2145. ?>
  2146.  
  2147. <tr>
  2148. <td colspan="5" style="text-align: center;"><p><br/><?php _e('No fields have been added to this form layout yet.','appthemes') ?><br/><br/></p></td>
  2149. </tr>
  2150.  
  2151. <?php
  2152. } // end $results
  2153. ?>
  2154.  
  2155. </tbody>
  2156.  
  2157. </table>
  2158.  
  2159. <p class="submit">
  2160. <input class="btn button-primary" name="save" type="submit" value="<?php _e('Save Changes','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  2161. <input name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel','appthemes') ?>" />
  2162. <input name="formlayout" type="hidden" value="yes" />
  2163. <input name="form_owner" type="hidden" value="<?php $current_user->user_login ?>" />
  2164. </p>
  2165. </form>
  2166.  
  2167. </td>
  2168. <td>
  2169.  
  2170. <h3><?php _e('Available Fields','appthemes') ?></h3>
  2171.  
  2172. <form method="post" id="mainform" action="">
  2173.  
  2174.  
  2175. <div class="fields-panel">
  2176.  
  2177. <table class="widefat">
  2178. <thead>
  2179. <tr>
  2180. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"/></th>
  2181. <th scope="col"><?php _e('Field Name','appthemes') ?></th>
  2182. <th scope="col"><?php _e('Type','appthemes') ?></th>
  2183. </tr>
  2184. </thead>
  2185.  
  2186.  
  2187. <tbody>
  2188.  
  2189. <?php
  2190. // Select all available fields not currently on the form layout.
  2191. // Also exclude any core fields since they cannot be removed from the layout.
  2192. $sql = $wpdb->prepare( "SELECT f.field_id,f.field_label,f.field_type "
  2193. . "FROM $wpdb->cp_ad_fields f "
  2194. . "WHERE f.field_id "
  2195. . "NOT IN (SELECT m.field_id "
  2196. . "FROM $wpdb->cp_ad_meta m "
  2197. . "WHERE m.form_id = %s) "
  2198. . "AND f.field_perm <> '1'",
  2199. $_GET['id']);
  2200.  
  2201. $results = $wpdb->get_results( $sql );
  2202.  
  2203. if ( $results ) {
  2204.  
  2205. foreach ( $results as $result ) {
  2206. ?>
  2207.  
  2208. <tr class="even">
  2209. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $result->field_id; ?>" name="field_id[]"/></th>
  2210. <td><?php echo esc_html( translate( $result->field_label, 'appthemes' ) ); ?></td>
  2211. <td><?php echo $result->field_type; ?></td>
  2212. </tr>
  2213.  
  2214. <?php
  2215. } // end foreach
  2216.  
  2217. } else {
  2218. ?>
  2219.  
  2220. <tr>
  2221. <td colspan="4" style="text-align: center;"><p><br /><?php _e('No fields are available.','appthemes') ?><br /><br /></p></td>
  2222. </tr>
  2223.  
  2224. <?php
  2225. } // end $results
  2226. ?>
  2227.  
  2228. </tbody>
  2229.  
  2230. </table>
  2231.  
  2232. </div>
  2233.  
  2234. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Add Fields to Form Layout','appthemes') ?>" /></p>
  2235. <input name="form_id" type="hidden" value="<?php echo $_GET['id']; ?>" />
  2236. <input name="submitted" type="hidden" value="yes" />
  2237.  
  2238.  
  2239. </form>
  2240.  
  2241. </td>
  2242. </tr>
  2243. </table>
  2244.  
  2245. </div><!-- /wrap -->
  2246.  
  2247. <?php
  2248.  
  2249. break;
  2250.  
  2251.  
  2252.  
  2253. case 'delete':
  2254.  
  2255. // delete the form based on the form id
  2256. cp_delete_form($_GET['id']);
  2257. ?>
  2258. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting form layout.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2259. <meta http-equiv="refresh" content="0; URL=?page=layouts">
  2260.  
  2261. <?php
  2262. break;
  2263.  
  2264. default:
  2265.  
  2266. $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->cp_ad_forms ORDER BY id desc" ) );
  2267.  
  2268. ?>
  2269.  
  2270. <div class="wrap">
  2271. <div class="icon32" id="icon-themes"><br /></div>
  2272. <h2><?php _e('Form Layouts','appthemes'); ?>&nbsp;<a class="button add-new-h2" href="?page=layouts&amp;action=addform"><?php _e('Add New','appthemes') ?></a></h2>
  2273.  
  2274. <?php cp_admin_info_box(); ?>
  2275.  
  2276. <p class="admin-msg"><?php _e('Form layouts allow you to create your own custom ad submission forms. Each form is essentially a container for your fields and can be applied to one or all of your categories. If you do not create any form layouts, the default one will be used. To change the default form, create a new form layout and apply it to all categories.','appthemes') ?></p>
  2277.  
  2278. <table id="tblspacer" class="widefat fixed">
  2279.  
  2280. <thead>
  2281. <tr>
  2282. <th scope="col" style="width:35px;">&nbsp;</th>
  2283. <th scope="col"><?php _e('Name','appthemes') ?></th>
  2284. <th scope="col"><?php _e('Description','appthemes') ?></th>
  2285. <th scope="col"><?php _e('Categories','appthemes') ?></th>
  2286. <th scope="col" style="width:150px;"><?php _e('Modified','appthemes') ?></th>
  2287. <th scope="col" style="width:75px;"><?php _e('Status','appthemes') ?></th>
  2288. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  2289. </tr>
  2290. </thead>
  2291.  
  2292. <?php
  2293. if ( $results ) {
  2294. $rowclass = '';
  2295. $i=1;
  2296. ?>
  2297.  
  2298. <tbody id="list">
  2299.  
  2300. <?php
  2301. foreach ( $results as $result ) {
  2302.  
  2303. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  2304. ?>
  2305.  
  2306. <tr class="<?php echo $rowclass ?>">
  2307. <td style="padding-left:10px;"><?php echo $i ?>.</td>
  2308. <td><a href="?page=layouts&amp;action=editform&amp;id=<?php echo $result->id ?>"><strong><?php echo $result->form_label ?></strong></a></td>
  2309. <td><?php echo $result->form_desc ?></td>
  2310. <td><?php echo cp_match_cats( unserialize($result->form_cats) ) ?></td>
  2311. <td><?php echo mysql2date( get_option('date_format') .' '. get_option('time_format'), $result->form_modified ) ?> <?php _e('by','appthemes') ?> <?php echo $result->form_owner; ?></td>
  2312. <td><?php echo ucfirst( $result->form_status ) ?></td>
  2313. <td style="text-align:center"><a href="?page=layouts&amp;action=formbuilder&amp;id=<?php echo $result->id ?>&amp;title=<?php echo urlencode($result->form_label) ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/layout_add.png" alt="<?php echo _e('Edit form layout','appthemes') ?>" title="<?php echo _e('Edit form layout','appthemes') ?>" /></a>&nbsp;&nbsp;&nbsp;
  2314. <a href="?page=layouts&amp;action=editform&amp;id=<?php echo $result->id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/edit.png" alt="<?php echo _e('Edit form properties','appthemes') ?>" title="<?php echo _e('Edit form properties','appthemes') ?>" /></a>&nbsp;&nbsp;&nbsp;
  2315. <a onclick="return confirmBeforeDelete();" href="?page=layouts&amp;action=delete&amp;id=<?php echo $result->id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/cross.png" alt="<?php echo _e('Delete form layout','appthemes') ?>" title="<?php echo _e('Delete form layout','appthemes') ?>" /></a></td>
  2316. </tr>
  2317.  
  2318. <?php
  2319.  
  2320. $i++;
  2321.  
  2322. } // end for each
  2323. ?>
  2324.  
  2325. </tbody>
  2326.  
  2327. <?php
  2328.  
  2329. } else {
  2330.  
  2331. ?>
  2332.  
  2333. <tr>
  2334. <td colspan="7"><?php _e('No form layouts found.','appthemes') ?></td>
  2335. </tr>
  2336.  
  2337. <?php
  2338. } // end $results
  2339. ?>
  2340.  
  2341. </table>
  2342.  
  2343.  
  2344. </div><!-- end wrap -->
  2345.  
  2346. <?php
  2347. } // end switch
  2348. ?>
  2349. <script type="text/javascript">
  2350. /* <![CDATA[ */
  2351. function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this?', 'appthemes'); ?>"); }
  2352. function confirmBeforeRemove() { return confirm("<?php _e('Are you sure you want to remove this?', 'appthemes'); ?>"); }
  2353. /* ]]> */
  2354. </script>
  2355.  
  2356. <?php
  2357.  
  2358. } // end function
  2359.  
  2360.  
  2361. function cp_custom_fields() {
  2362. global $options_new_field, $wpdb, $current_user;
  2363.  
  2364. $current_user = wp_get_current_user();
  2365. ?>
  2366.  
  2367. <!-- show/hide the dropdown field values tr -->
  2368. <script type="text/javascript">
  2369. /* <![CDATA[ */
  2370. jQuery(document).ready(function() {
  2371. jQuery("#mainform").validate({errorClass: "invalid"});
  2372. });
  2373.  
  2374. function show(o){
  2375. if(o){switch(o.value){
  2376. case 'drop-down': jQuery('#field_values_row').show(); jQuery('#field_min_length_row').hide(); break;
  2377. case 'radio': jQuery('#field_values_row').show(); jQuery('#field_min_length_row').hide(); break;
  2378. case 'checkbox': jQuery('#field_values_row').show(); jQuery('#field_min_length_row').hide(); break;
  2379. case 'text box': jQuery('#field_min_length_row').show(); jQuery('#field_values_row').hide(); break;
  2380. default: jQuery('#field_values_row').hide();jQuery('#field_min_length_row').hide();
  2381. }}
  2382. }
  2383.  
  2384. //show/hide immediately on document load
  2385. jQuery(document).ready(function() {
  2386. show(jQuery('#field_type').get(0));
  2387. });
  2388.  
  2389. //hide unwanted options for cp_currency field
  2390. jQuery(document).ready(function() {
  2391. var field_name = jQuery('#field_name').val();
  2392. if(field_name == 'cp_currency'){
  2393. jQuery("#field_type option[value='text box']").attr("disabled","disabled");
  2394. jQuery("#field_type option[value='text area']").attr("disabled","disabled");
  2395. jQuery("#field_type option[value='checkbox']").attr("disabled","disabled");
  2396. }
  2397. });
  2398. /* ]]> */
  2399. </script>
  2400.  
  2401. <?php
  2402.  
  2403. // check to prevent php "notice: undefined index" msg when php strict warnings is on
  2404. if ( isset( $_GET['action'] ) ) $theswitch = $_GET['action']; else $theswitch = '';
  2405.  
  2406. switch ( $theswitch ) {
  2407.  
  2408. case 'addfield':
  2409. ?>
  2410.  
  2411. <div class="wrap">
  2412. <div class="icon32" id="icon-themes"><br /></div>
  2413. <h2><?php _e('New Custom Field','appthemes') ?></h2>
  2414.  
  2415. <?php cp_admin_info_box(); ?>
  2416.  
  2417. <?php
  2418. // check and make sure the form was submitted
  2419. if ( isset( $_POST['submitted'] ) ) {
  2420.  
  2421. $_POST['field_search'] = ''; // we aren't using this field so set it to blank for now to prevent notice
  2422.  
  2423. $insert = "INSERT INTO $wpdb->cp_ad_fields ( field_name, field_label, field_desc, field_tooltip, field_type, field_values, field_search, field_owner, field_created, field_modified ) VALUES ( '" .
  2424. $wpdb->escape(appthemes_clean(cp_make_custom_name($_POST['field_label']))) . "','" .
  2425. $wpdb->escape(appthemes_clean($_POST['field_label'])) . "','" .
  2426. $wpdb->escape(appthemes_clean($_POST['field_desc'])) . "','" .
  2427. $wpdb->escape(esc_attr(appthemes_clean($_POST['field_tooltip']))) . "','" .
  2428. $wpdb->escape(appthemes_clean($_POST['field_type'])) . "','" .
  2429. $wpdb->escape(appthemes_clean($_POST['field_values'])) . "','" .
  2430. $wpdb->escape(appthemes_clean($_POST['field_search'])) . "','" .
  2431. $wpdb->escape(appthemes_clean($_POST['field_owner'])) . "','" .
  2432. current_time('mysql') . "','" .
  2433. current_time('mysql') .
  2434. "' )";
  2435.  
  2436. $results = $wpdb->query( $insert );
  2437.  
  2438.  
  2439. if ( $results ) :
  2440.  
  2441. //$lastid = $wpdb->insert_id;
  2442. //echo $lastid;
  2443. ?>
  2444.  
  2445. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Creating your field.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2446. <meta http-equiv="refresh" content="0; URL=?page=fields">
  2447.  
  2448. <?php
  2449. endif;
  2450.  
  2451. die;
  2452.  
  2453. } else {
  2454. ?>
  2455.  
  2456. <form method="post" id="mainform" action="">
  2457.  
  2458. <?php cp_admin_fields( $options_new_field ) ?>
  2459.  
  2460. <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Create New Field','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  2461. <input name="cancel" type="button" onClick="location.href='?page=fields'" value="<?php _e('Cancel','appthemes') ?>" /></p>
  2462. <input name="submitted" type="hidden" value="yes" />
  2463. <input name="field_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  2464.  
  2465. </form>
  2466.  
  2467. <?php
  2468. }
  2469. ?>
  2470.  
  2471. </div><!-- end wrap -->
  2472.  
  2473. <?php
  2474. break;
  2475.  
  2476.  
  2477. case 'editfield':
  2478. ?>
  2479.  
  2480. <div class="wrap">
  2481. <div class="icon32" id="icon-themes"><br /></div>
  2482. <h2><?php _e('Edit Custom Field','appthemes') ?></h2>
  2483.  
  2484. <?php cp_admin_info_box(); ?>
  2485.  
  2486. <?php
  2487. if ( isset( $_POST['submitted'] ) && $_POST['submitted'] == 'yes' ) {
  2488.  
  2489. // @todo Change to Update
  2490. $update = $wpdb->prepare( "UPDATE $wpdb->cp_ad_fields SET" .
  2491. " field_name = %s," .
  2492. " field_label = %s," .
  2493. " field_desc = %s," .
  2494. " field_tooltip = %s," .
  2495. " field_type = %s," .
  2496. " field_values = %s," .
  2497. " field_min_length = %s," .
  2498. // " field_search = '" . $wpdb->escape(appthemes_clean($_POST['field_search'])) . "'," .
  2499. " field_owner = %s," .
  2500. " field_modified = %s" .
  2501. /tableCDATA " WHERE field_id = %s",
  2502. appthemes_clean($_POST['field_name']),
  2503. appthemes_clean($_POST['field_label']),
  2504. appthemes_clean($_POST['field_desc']),
  2505. esc_attr(appthemes_clean($_POST['field_tooltip'])),
  2506. appthemes_clean($_POST['field_type']),
  2507. appthemes_clean($_POST['field_values']),
  2508. appthemes_clean($_POST['field_min_length']),
  2509. appthemes_clean($_POST['field_owner']),
  2510. current_time('mysql'),
  2511. $_GET['id']
  2512. );
  2513.  
  2514. $results = $wpdb->query( $update );
  2515.  
  2516. ?>
  2517.  
  2518. <p style="text-align:center;padding-top:50px;font-size:22px;">
  2519.  
  2520. <?php _e('Saving your changes.....', 'appthemes') ?><br /><br />
  2521. <img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" />
  2522.  
  2523. </p>
  2524.  
  2525. <meta http-equiv="refresh" content="0; URL=?page=fields">
  2526.  
  2527. <?php
  2528. } else {
  2529. ?>
  2530.  
  2531.  
  2532. <form method="post" id="mainform" action="">
  2533.  
  2534. <?php cp_admin_db_fields($options_new_field, 'cp_ad_fields', 'field_id') ?>
  2535.  
  2536. <p class="submit">
  2537. <input class="btn button-primary" name="save" type="submit" value="<?php _e('Save changes','appthemes') ?>" />&nbsp;&nbsp;&nbsp;
  2538. <input name="cancel" type="button" onClick="location.href='?page=fields'" value="<?php _e('Cancel','appthemes') ?>" />
  2539. <input name="submitted" type="hidden" value="yes" />
  2540. <input name="field_owner" type="hidden" value="<?php echo $current_user->user_login ?>" />
  2541. </p>
  2542.  
  2543. </form>
  2544.  
  2545. <?php } ?>
  2546.  
  2547. </div><!-- end wrap -->
  2548.  
  2549. <?php
  2550. break;
  2551.  
  2552.  
  2553. case 'delete':
  2554.  
  2555. // check and make sure this fields perms allow deletion
  2556. $sql = "SELECT field_perm "
  2557. . "FROM $wpdb->cp_ad_fields "
  2558. . "WHERE field_id = '". $_GET['id'] ."' LIMIT 1";
  2559.  
  2560. $results = $wpdb->get_row( $sql );
  2561.  
  2562. // if it's not greater than zero, then delete it
  2563. if ( !$results->field_perm > 0 ) {
  2564.  
  2565. $delete = "DELETE FROM $wpdb->cp_ad_fields WHERE field_id = '". $_GET['id'] ."'";
  2566.  
  2567. $wpdb->query( $delete );
  2568. }
  2569. ?>
  2570. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting custom field.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2571. <meta http-equiv="refresh" content="0; URL=?page=fields">
  2572.  
  2573. <?php
  2574.  
  2575. break;
  2576.  
  2577.  
  2578. // cp_custom_fields() show the table of all custom fields
  2579. default:
  2580.  
  2581. $sql = "SELECT field_id, field_name, field_label, field_desc, field_tooltip, field_type, field_perm, field_owner, field_modified "
  2582. . "FROM $wpdb->cp_ad_fields "
  2583. . "ORDER BY field_name desc";
  2584.  
  2585. $results = $wpdb->get_results($sql);
  2586. ?>
  2587.  
  2588. <div class="wrap">
  2589. <div class="icon32" id="icon-tools"><br /></div>
  2590. <h2><?php _e('Custom Fields','appthemes') ?>&nbsp;<a class="button add-new-h2" href="?page=fields&amp;action=addfield"><?php _e('Add New','appthemes') ?></a></h2>
  2591.  
  2592. <?php cp_admin_info_box(); ?>
  2593.  
  2594. <p class="admin-msg"><?php _e('Custom fields allow you to customize your ad submission forms and collect more information. Each custom field needs to be added to a form layout in order to be visible on your website. You can create unlimited custom fields and each one can be used across multiple form layouts. It is highly recommended to NOT delete a custom field once it is being used on your ads because it could cause ad editing problems for your customers.','appthemes') ?></p>
  2595.  
  2596. <table id="tblspacer" class="widefat fixed">
  2597.  
  2598. <thead>
  2599. <tr>
  2600. <th scope="col" style="width:35px;">&nbsp;</th>
  2601. <th scope="col"><?php _e('Name','appthemes') ?></th>
  2602. <th scope="col" style="width:100px;"><?php _e('Type','appthemes') ?></th>
  2603. <th scope="col"><?php _e('Description','appthemes') ?></th>
  2604. <th scope="col" style="width:150px;"><?php _e('Modified','appthemes') ?></th>
  2605. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  2606. </tr>
  2607. </thead>
  2608.  
  2609. <?php
  2610. if ($results) {
  2611. ?>
  2612.  
  2613. <tbody id="list">
  2614.  
  2615. <?php
  2616. $rowclass = '';
  2617. $i=1;
  2618.  
  2619. foreach($results as $result) {
  2620.  
  2621. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  2622. ?>
  2623.  
  2624. <tr class="<?php echo $rowclass ?>">
  2625. <td style="padding-left:10px;"><?php echo $i ?>.</td>
  2626. <td><a href="?page=fields&amp;action=editfield&amp;id=<?php echo $result->field_id ?>"><strong><?php echo esc_html( translate( $result->field_label, 'appthemes') ); ?></strong></a></td>
  2627. <td><?php echo $result->field_type ?></td>
  2628. <td><?php echo esc_html( translate( $result->field_desc, 'appthemes' ) ); ?></td>
  2629. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->field_modified) ?> <?php _e('by', 'appthemes') ?> <?php echo $result->field_owner; ?></td>
  2630. <td style="text-align:center">
  2631.  
  2632. <?php
  2633. // show the correct edit options based on perms
  2634. switch($result->field_perm) {
  2635.  
  2636. case '1': // core fields no editing
  2637. ?>
  2638.  
  2639. <a href="?page=fields&amp;action=editfield&amp;id=<?php echo $result->field_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/edit.png" alt="" /></a>&nbsp;&nbsp;&nbsp;
  2640. <img src="<?php echo bloginfo('template_directory'); ?>/images/cross-grey.png" alt="" />
  2641.  
  2642. <?php
  2643. break;
  2644.  
  2645. case '2': // core fields some editing
  2646. ?>
  2647.  
  2648. <a href="?page=fields&amp;action=editfield&amp;id=<?php echo $result->field_id ?>"><img src="<?php echo bloginfo('template_directory') ?>/images/edit.png" alt="" /></a>&nbsp;&nbsp;&nbsp;
  2649. <img src="<?php echo bloginfo('template_directory') ?>/images/cross-grey.png" alt="" />
  2650.  
  2651. <?php
  2652. break;
  2653.  
  2654. default: // regular fields full editing
  2655. // don't change these two lines to plain html/php. Get t_else error msg
  2656. echo '<a href="?page=fields&amp;action=editfield&amp;id='. $result->field_id .'"><img src="'. get_bloginfo('template_directory') .'/images/edit.png" alt="" /></a>&nbsp;&nbsp;&nbsp;';
  2657. echo '<a onclick="return confirmBeforeDelete();" href="?page=fields&amp;action=delete&amp;id='. $result->field_id .'"><img src="'. get_bloginfo('template_directory') .'/images/cross.png" alt="" /></a>';
  2658.  
  2659. } // endswitch
  2660. ?>
  2661.  
  2662. </td>
  2663. </tr>
  2664.  
  2665. <?php
  2666. $i++;
  2667.  
  2668. } //end foreach;
  2669. //} // mystery bracket which makes it work
  2670. ?>
  2671.  
  2672. </tbody>
  2673.  
  2674. <?php
  2675. } else {
  2676. ?>
  2677.  
  2678. <tr>
  2679. <td colspan="5"><?php _e('No custom fields found. This usually means your install script did not run correctly. Go back and try reactivating the theme again.','appthemes') ?></td>
  2680. </tr>
  2681.  
  2682. <?php
  2683. } // end $results
  2684. ?>
  2685.  
  2686. </table>
  2687.  
  2688. </div><!-- end wrap -->
  2689.  
  2690. <?php
  2691. } // endswitch
  2692. ?>
  2693.  
  2694.  
  2695.  
  2696. <script type="text/javascript">
  2697. /* <![CDATA[ */
  2698. function confirmBeforeDelete() { return confirm("<?php _e('WARNING: Deleting this field will prevent any existing ads currently using this field from displaying the field value. Deleting fields is NOT recommended unless you do not have any existing ads using this field. Are you sure you want to delete this field?? (This cannot be undone)', 'appthemes'); ?>"); }
  2699. /* ]]> */
  2700. </script>
  2701.  
  2702. <?php
  2703.  
  2704. } // end function
  2705.  
  2706.  
  2707. // deletes all the ClassiPress database tables
  2708. function cp_delete_db_tables() {
  2709. global $wpdb, $app_db_tables;
  2710.  
  2711. echo '<p class="info">';
  2712.  
  2713. foreach ( $app_db_tables as $key => $value ) {
  2714. $sql = "DROP TABLE IF EXISTS ". $wpdb->prefix . $value;
  2715. $wpdb->query($sql);
  2716.  
  2717. printf( __("Table '%s' has been deleted.", 'appthemes'), $value);
  2718. echo '<br/>';
  2719. }
  2720.  
  2721. echo '</p>';
  2722. }
  2723.  
  2724.  
  2725. // deletes all the ClassiPress database tables
  2726. function cp_delete_all_options() {
  2727. global $wpdb;
  2728.  
  2729. $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name like 'cp_%'" );
  2730. echo '<p class="info">' . __('All ClassiPress options have been deleted from the WordPress options table.', 'appthemes') . '</p>';
  2731. }
  2732.  
  2733. // flushes the caches
  2734. function cp_flush_all_cache() {
  2735. global $wpdb, $app_transients;
  2736.  
  2737. $output = '';
  2738.  
  2739. foreach ( $app_transients as $key => $value ) :
  2740. delete_transient($value);
  2741. $output .= sprintf('<br />'.__("ClassiPress '%s' cache has been flushed.", 'appthemes' . '<br />'), $value);
  2742. endforeach;
  2743.  
  2744. return $output;
  2745.  
  2746. }
  2747.  
  2748. // show all the order transactions
  2749. function cp_transactions() {
  2750. global $wpdb;
  2751. include_once (TEMPLATEPATH . '/includes/forms/step-functions.php');
  2752.  
  2753. if (isset($_GET['p'])) $page = (int)$_GET['p']; else $page = 1;
  2754. $per_page = 10;
  2755. $start = ($per_page * $page) - $per_page;
  2756.  
  2757. // check to prevent php "notice: undefined index" msg when php strict warnings is on
  2758. if ( isset( $_GET['action'] ) ) $theswitch = $_GET['action']; else $theswitch = '';
  2759.  
  2760. switch ( $theswitch ) {
  2761.  
  2762. // mark transaction as paid
  2763. case 'setPaid':
  2764.  
  2765. $update = "UPDATE $wpdb->cp_order_info SET payment_status = 'Completed' WHERE id = '". $_GET['id'] ."'";
  2766. $wpdb->query( $update );
  2767. ?>
  2768. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Updating transaction entry.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2769. <meta http-equiv="refresh" content="0; URL=?page=transactions">
  2770.  
  2771. <?php
  2772.  
  2773. break;
  2774.  
  2775.  
  2776. // mark transaction as unpaid
  2777. case 'unsetPaid':
  2778.  
  2779. $update = "UPDATE $wpdb->cp_order_info SET payment_status = 'Pending' WHERE id = '". $_GET['id'] ."'";
  2780. $wpdb->query( $update );
  2781. ?>
  2782. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Updating transaction entry.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2783. <meta http-equiv="refresh" content="0; URL=?page=transactions">
  2784.  
  2785. <?php
  2786.  
  2787. break;
  2788.  
  2789.  
  2790. // delete transaction entry
  2791. case 'delete':
  2792.  
  2793. $delete = "DELETE FROM $wpdb->cp_order_info WHERE id = '". $_GET['id'] ."'";
  2794. $wpdb->query( $delete );
  2795. ?>
  2796. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting transaction entry.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2797. <meta http-equiv="refresh" content="0; URL=?page=transactions">
  2798.  
  2799. <?php
  2800.  
  2801. break;
  2802.  
  2803.  
  2804. // activate membership, update transaction entry
  2805. case 'activateMembership':
  2806.  
  2807. $orders = get_user_orders('',$_GET['oid']);
  2808. if(!empty($orders)){
  2809. $order_id = get_order_id($orders);
  2810. $storedOrder = get_option($orders);
  2811. $user_id = get_order_userid($orders);
  2812. $the_user = get_userdata($user_id);
  2813. //activate membership
  2814. $order_processed = appthemes_process_membership_order($the_user, $storedOrder);
  2815. //send email to user
  2816. if($order_processed)
  2817. cp_owner_activated_membership_email($the_user, $order_processed);
  2818. //update transaction entry
  2819. $update = "UPDATE $wpdb->cp_order_info SET payment_status = 'Completed' WHERE custom = '". $_GET['oid'] ."'";
  2820. $wpdb->query( $update );
  2821. }
  2822. ?>
  2823. <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Activating membership plan.....','appthemes') ?><br /><br /><img src="<?php echo bloginfo('template_directory') ?>/images/loader.gif" alt="" /></p>
  2824. <meta http-equiv="refresh" content="0; URL=?page=transactions">
  2825.  
  2826. <?php
  2827.  
  2828. break;
  2829.  
  2830.  
  2831. // show the table of all transactions
  2832. default:
  2833. ?>
  2834. <div class="wrap">
  2835. <div class="icon32" id="icon-themes"><br /></div>
  2836. <h2><?php _e('Order Transactions','appthemes') ?></h2>
  2837.  
  2838. <?php cp_admin_info_box(); ?>
  2839.  
  2840. <table id="tblspacer" class="widefat fixed">
  2841.  
  2842. <thead>
  2843. <tr>
  2844. <th scope="col" style="width:35px;">&nbsp;</th>
  2845. <th scope="col"><?php _e('Payer Name','appthemes') ?></th>
  2846. <th scope="col" style="text-align: center;"><?php _e('Payer Status','appthemes') ?></th>
  2847. <th scope="col"><?php _e('Ad Title','appthemes') ?></th>
  2848. <th scope="col"><?php _e('Item Description','appthemes') ?></th>
  2849. <th scope="col" style="width:125px;"><?php _e('Transaction ID','appthemes') ?></th>
  2850. <th scope="col"><?php _e('Payment Type','appthemes') ?></th>
  2851. <th scope="col"><?php _e('Payment Status','appthemes') ?></th>
  2852. <th scope="col"><?php _e('Total Amount','appthemes') ?></th>
  2853. <th scope="col" style="width:150px;"><?php _e('Date Paid','appthemes') ?></th>
  2854. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  2855. </tr>
  2856. </thead>
  2857.  
  2858. <?php
  2859. // must be higher than personal edition so let's query the db
  2860. $sql = "SELECT SQL_CALC_FOUND_ROWS o.*, p.post_title "
  2861. . "FROM $wpdb->cp_order_info o, $wpdb->posts p "
  2862. . "WHERE o.ad_id = p.id "
  2863. . "ORDER BY o.id DESC LIMIT $start,$per_page";
  2864.  
  2865. $results = $wpdb->get_results( $sql );
  2866.  
  2867. $total_pages = $wpdb->get_var( $wpdb->prepare("SELECT FOUND_ROWS()") );
  2868. $total_pages = ceil($total_pages/$per_page);
  2869.  
  2870. if ( $results ) {
  2871. $rowclass = '';
  2872. $i=1;
  2873. ?>
  2874.  
  2875. <tbody id="list">
  2876.  
  2877. <?php
  2878. foreach ( $results as $result ) {
  2879.  
  2880. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  2881. ?>
  2882.  
  2883. <tr class="<?php echo $rowclass ?>">
  2884. <td style="padding-left:10px;"><?php echo $i ?>.</td>
  2885.  
  2886. <td><strong><?php echo $result->first_name ?> <?php echo $result->last_name ?></strong><br /><a href="mailto:<?php echo $result->payer_email ?>"><?php echo $result->payer_email ?></a></td>
  2887. <td style="text-align: center;">
  2888. <?php if ($result->payer_status == 'verified') { ?><img src="<?php bloginfo('template_directory'); ?>/images/paypal_verified.gif" alt="" title="" /><br /><?php } ?>
  2889. <?php echo ucfirst($result->payer_status) ?>
  2890. </td>
  2891. <td><a href="post.php?action=edit&post=<?php echo $result->ad_id ?>"><?php echo $result->post_title ?></a></td>
  2892. <td><?php echo $result->item_name ?></td>
  2893. <td><?php echo $result->txn_id ?></td>
  2894. <td><?php echo ucfirst($result->payment_type) ?></td>
  2895. <td><?php echo ucfirst($result->payment_status) ?></td>
  2896. <td><?php echo $result->mc_gross ?> <?php echo $result->mc_currency ?></td>
  2897. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->payment_date) ?></td>
  2898. <td style="text-align:center">
  2899. <?php
  2900. echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id='. $result->id .'" title="'. __('Delete', 'appthemes') .'"><img src="'. get_bloginfo('template_directory') .'/images/cross.png" alt="'. __('Delete', 'appthemes') .'" /></a>&nbsp;&nbsp;&nbsp;';
  2901. if(strtolower($result->payment_status) == 'completed')
  2902. echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id='. $result->id .'" title="'. __('Mark as Unpaid', 'appthemes') .'">'. __('Unmark Paid', 'appthemes') .'</a>';
  2903. else
  2904. echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id='. $result->id .'" title="'. __('Mark as Paid', 'appthemes') .'">'. __('Mark Paid', 'appthemes') .'</a>';
  2905. ?>
  2906. </td>
  2907. </tr>
  2908.  
  2909. <?php
  2910.  
  2911. $i++;
  2912.  
  2913. } // end for each
  2914. ?>
  2915.  
  2916. </tbody>
  2917.  
  2918. <?php
  2919.  
  2920. } else {
  2921.  
  2922. ?>
  2923.  
  2924. <tr>
  2925. <td>&nbsp;</td><td colspan="10"><?php _e('No transactions found.','appthemes') ?></td>
  2926. </tr>
  2927.  
  2928. <?php
  2929. } // end $results
  2930. ?>
  2931.  
  2932. </table> <!-- this is ok -->
  2933.  
  2934. <div class="tablenav">
  2935. <div class="tablenav-pages alignright">
  2936. <?php
  2937. if ( $total_pages > 1 ) {
  2938. echo paginate_links( array(
  2939. 'base' => 'admin.php?page=transactions%_%',
  2940. 'format' => '&p=%#%',
  2941. 'prev_text' => __('&laquo; Previous'),
  2942. 'next_text' => __('Next &raquo;'),
  2943. 'total' => $total_pages,
  2944. 'current' => $page,
  2945. 'end_size' => 1,
  2946. 'mid_size' => 5,
  2947. ));
  2948. }
  2949. ?>
  2950. </div>
  2951. </div>
  2952. <div class="clear"></div>
  2953.  
  2954.  
  2955. <div class="icon32" id="icon-themes"><br /></div>
  2956. <h2><?php _e('Membership Orders','appthemes') ?></h2>
  2957. <table id="tblspacer" class="widefat fixed">
  2958.  
  2959. <thead>
  2960. <tr>
  2961. <th scope="col" style="width:35px;">&nbsp;</th>
  2962. <th scope="col"><?php _e('Payer Name','appthemes') ?></th>
  2963. <th scope="col" style="text-align: center;"><?php _e('Payer Status','appthemes') ?></th>
  2964. <th scope="col"><?php _e('Item Description','appthemes') ?></th>
  2965. <th scope="col" style="width:125px;"><?php _e('Transaction ID','appthemes') ?></th>
  2966. <th scope="col"><?php _e('Payment Type','appthemes') ?></th>
  2967. <th scope="col"><?php _e('Payment Status','appthemes') ?></th>
  2968. <th scope="col"><?php _e('Total Amount','appthemes') ?></th>
  2969. <th scope="col" style="width:150px;"><?php _e('Date Paid','appthemes') ?></th>
  2970. <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions','appthemes') ?></th>
  2971. </tr>
  2972. </thead>
  2973.  
  2974.  
  2975. <?php
  2976. // seperate table for membership orders
  2977. $sql = "SELECT SQL_CALC_FOUND_ROWS * "
  2978. . "FROM $wpdb->cp_order_info "
  2979. . "WHERE ad_id = 0 "
  2980. . "ORDER BY id DESC LIMIT $start,$per_page";
  2981.  
  2982. $results = $wpdb->get_results($sql);
  2983.  
  2984. $total_pages = $wpdb->get_var( $wpdb->prepare("SELECT FOUND_ROWS()") );
  2985. $total_pages = ceil($total_pages/$per_page);
  2986.  
  2987. if ($results) {
  2988. $rowclass = '';
  2989. $i=1;
  2990. ?>
  2991.  
  2992. <tbody id="list">
  2993.  
  2994. <?php
  2995. foreach ( $results as $result ) {
  2996.  
  2997. $rowclass = 'even' == $rowclass ? 'alt' : 'even';
  2998. ?>
  2999.  
  3000. <tr class="<?php echo $rowclass ?>">
  3001. <td style="padding-left:10px;"><?php echo $i ?>.</td>
  3002. <?php $payer = get_user_by('email', $result->payer_email); ?>
  3003. <?php //TODO - LOOKUP CUSTOMER BY PAYPAL EMAIL CUSTOM PROFILE FIELD ?>
  3004. <td><strong><?php echo $result->first_name ?> <?php echo $result->last_name ?></strong><br /><a href="<?php if(isset($payer->ID) && $payer) echo get_bloginfo('url').'/wp-admin/user-edit.php?user_id='.$payer->ID; else echo 'mailto:'.$result->payer_email; ?>"><?php echo $result->payer_email ?></a></td>
  3005. <td style="text-align: center;">
  3006. <?php if ($result->payer_status == 'verified') { ?><img src="<?php bloginfo('template_directory'); ?>/images/paypal_verified.gif" alt="" title="" /><br /><?php } ?>
  3007. <?php echo ucfirst($result->payer_status) ?>
  3008. </td>
  3009. <td><?php echo $result->item_name ?></td>
  3010. <td><?php echo $result->txn_id ?></td>
  3011. <td><?php echo ucfirst($result->payment_type) ?></td>
  3012. <td><?php echo ucfirst($result->payment_status) ?></td>
  3013. <td><?php echo $result->mc_gross ?> <?php echo $result->mc_currency ?></td>
  3014. <td><?php echo mysql2date(get_option('date_format') .' '. get_option('time_format'), $result->payment_date) ?></td>
  3015. <td style="text-align:center">
  3016. <?php
  3017. echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id='. $result->id .'" title="'. __('Delete', 'appthemes') .'"><img src="'. get_bloginfo('template_directory') .'/images/cross.png" alt="'. __('Delete', 'appthemes') .'" /></a>&nbsp;&nbsp;&nbsp;';
  3018. if(strtolower($result->payment_status) == 'completed')
  3019. echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id='. $result->id .'" title="'. __('Mark as Unpaid', 'appthemes') .'">'. __('Unmark Paid', 'appthemes') .'</a>';
  3020. else {
  3021. echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id='. $result->id .'" title="'. __('Mark as Paid', 'appthemes') .'">'. __('Mark Paid', 'appthemes') .'</a>';
  3022. if(!empty($result->custom)) $orders = get_user_orders('',$result->custom); else $orders = '';
  3023. if(!empty($orders))
  3024. echo '<br /><a href="?page=transactions&amp;action=activateMembership&amp;oid='. $result->custom .'" title="'. __('Activate membership', 'appthemes') .'">'. __('Activate membership', 'appthemes') .'</a>';
  3025. }
  3026. ?>
  3027. </td>
  3028. </tr>
  3029.  
  3030. <?php
  3031.  
  3032. $i++;
  3033.  
  3034. } // end for each
  3035. ?>
  3036.  
  3037. </tbody>
  3038.  
  3039. <?php
  3040.  
  3041. } else {
  3042.  
  3043. ?>
  3044.  
  3045. <tr>
  3046. <td>&nbsp;</td><td colspan="9"><?php _e('No transactions found.','appthemes') ?></td>
  3047. </tr>
  3048.  
  3049. <?php
  3050. } // end $results
  3051. ?>
  3052.  
  3053. </table> <!-- this is ok -->
  3054.  
  3055. <div class="tablenav">
  3056. <div class="tablenav-pages alignright">
  3057. <?php
  3058. if ( $total_pages > 1 ) {
  3059. echo paginate_links( array(
  3060. 'base' => 'admin.php?page=transactions%_%',
  3061. 'format' => '&p=%#%',
  3062. 'prev_text' => __('&laquo; Previous'),
  3063. 'next_text' => __('Next &raquo;'),
  3064. 'total' => $total_pages,
  3065. 'current' => $page,
  3066. 'end_size' => 1,
  3067. 'mid_size' => 5,
  3068. ));
  3069. }
  3070. ?>
  3071. </div>
  3072. </div>
  3073. <div class="clear"></div>
  3074.  
  3075.  
  3076. </div><!-- end wrap -->
  3077.  
  3078. <?php
  3079. } // endswitch
  3080. ?>
  3081.  
  3082.  
  3083.  
  3084. <script type="text/javascript">
  3085. /* <![CDATA[ */
  3086. function confirmBeforeDelete() { return confirm("<?php _e('WARNING: Are you sure you want to delete this transaction entry?? (This cannot be undone)', 'appthemes'); ?>"); }
  3087. /* ]]> */
  3088. </script>
  3089.  
  3090. <?php
  3091.  
  3092. }
  3093.  
  3094.  
  3095. // system information page
  3096. function cp_system_info() {
  3097. global $wpdb, $system_info, $app_version;
  3098. ?>
  3099.  
  3100. <div class="wrap">
  3101. <div class="icon32" id="icon-options-general"><br/></div>
  3102. <h2><?php _e('ClassiPress System Info','appthemes') ?></h2>
  3103.  
  3104. <?php cp_admin_info_box(); ?>
  3105.  
  3106. <?php
  3107. // delete all the db tables if the button has been pressed.
  3108. if ( isset($_POST['deletetables']) )
  3109. cp_delete_db_tables();
  3110.  
  3111. // delete all the cp config options from the wp_options table if the button has been pressed.
  3112. if ( isset($_POST['deleteoptions']) )
  3113. cp_delete_all_options();
  3114.  
  3115. // flush the cache if the button has been pressed.
  3116. if ( isset($_POST['flushcache']) )
  3117. echo cp_flush_all_cache();
  3118.  
  3119. // reinstall completed
  3120. if ( isset($_GET['reinstall']) )
  3121. echo '<p class="info">'. __('ClassiPress was successfully reinstalled.', 'appthemes') . '</p>';
  3122. ?>
  3123.  
  3124. <script type="text/javascript">
  3125. jQuery(function() {
  3126. jQuery("#tabs-wrap").tabs({
  3127. fx: {
  3128. opacity: 'toggle',
  3129. duration: 200
  3130. }
  3131. });
  3132. });
  3133. </script>
  3134.  
  3135. <div id="tabs-wrap">
  3136. <ul class="tabs">
  3137. <li><a href="#tab0"><?php _e('Debug Info','appthemes')?></a></li>
  3138. <li><a href="#tab1"><?php _e('Cron Jobs','appthemes')?></a></li>
  3139. <li><a href="#tab2"><?php _e('Advanced','appthemes')?></a></li>
  3140. </ul>
  3141.  
  3142. <div id="tab0">
  3143.  
  3144.  
  3145. <table class="widefat fixed" style="width:850px;">
  3146.  
  3147. <thead>
  3148. <tr>
  3149. <th scope="col" width="200px"><?php _e('Theme Info','appthemes')?></th>
  3150. <th scope="col">&nbsp;</th>
  3151. </tr>
  3152. </thead>
  3153.  
  3154. <tbody>
  3155. <tr>
  3156. <td class="titledesc"><?php _e('ClassiPress Version','appthemes')?></td>
  3157. <td class="forminp"><?php echo $app_version; ?></td>
  3158. </tr>
  3159.  
  3160. <tr>
  3161. <td class="titledesc"><?php _e('ClassiPress DB Version','appthemes')?></td>
  3162. <td class="forminp"><?php echo get_option('cp_db_version'); ?></td>
  3163. </tr>
  3164.  
  3165. <tr>
  3166. <td class="titledesc"><?php _e('WordPress Version','appthemes')?></td>
  3167. <td class="forminp"><?php if (function_exists('bloginfo')) echo bloginfo('version'); ?> <?php if ( is_multisite() ) echo '- '.__('Multisite', 'appthemes'); ?></td>
  3168. </tr>
  3169.  
  3170. <tr>
  3171. <td class="titledesc"><?php _e('Theme Path','appthemes')?></td>
  3172. <td class="forminp"><?php if (function_exists('bloginfo')) echo bloginfo('template_url'); ?></td>
  3173. </tr>
  3174.  
  3175. <thead>
  3176. <tr>
  3177. <th scope="col" width="200px"><?php _e('Server Info','appthemes')?></th>
  3178. <th scope="col">&nbsp;</th>
  3179. </tr>
  3180. </thead>
  3181.  
  3182. <tr>
  3183. <td class="titledesc"><?php _e('PHP Version','appthemes')?></td>
  3184. <td class="forminp"><?php if (function_exists('phpversion')) echo phpversion(); ?></td>
  3185. </tr>
  3186.  
  3187. <tr>
  3188. <td class="titledesc"><?php _e('Server Software','appthemes')?></td>
  3189. <td class="forminp"><?php echo $_SERVER['SERVER_SOFTWARE']; ?></td>
  3190. </tr>
  3191.  
  3192. <tr>
  3193. <td class="titledesc"><?php _e('UPLOAD_MAX_FILESIZE','appthemes')?></td>
  3194. <td class="forminp"><?php if (function_exists('phpversion')) echo ini_get('upload_max_filesize'); ?></td>
  3195. </tr>
  3196.  
  3197. <tr>
  3198. <td class="titledesc"><?php _e('DISPLAY_ERRORS','appthemes')?></td>
  3199. <td class="forminp"><?php if (function_exists('phpversion')) echo ini_get('display_errors'); ?></td>
  3200. </tr>
  3201.  
  3202.  
  3203. <thead>
  3204. <tr>
  3205. <th scope="col" width="200px"><?php _e('Image Support','appthemes')?></th>
  3206. <th scope="col">&nbsp;</th>
  3207. </tr>
  3208. </thead>
  3209.  
  3210. <tr>
  3211. <td class="titledesc"><?php _e('GD Library Check','appthemes')?></td>
  3212. <td class="forminp"><?php if (extension_loaded('gd') && function_exists('gd_info')) echo '<font color="green">' . __('Your server supports the GD Library.', 'appthemes'). '</font>'; else echo '<font color="red">' . __('Your server does not have the GD Library enabled so the legacy image resizer script (TimThumb) will not work. Most servers with PHP 4.3+ includes this by default.', 'appthemes'). '</font>'; ?></td>
  3213. </tr>
  3214.  
  3215. <tr>
  3216. <td class="titledesc"><?php _e('Image Upload Path','appthemes')?></td>
  3217. <td class="forminp"><?php $uploads = wp_upload_dir(); echo $uploads['url'];?>
  3218. <?php if ( !appthemes_is_wpmu() ) printf( ' - <a href="%s">' . __('(change this)', 'appthemes') . '</a>', 'options-media.php' ); ?></td>
  3219. </tr>
  3220.  
  3221. <!--
  3222.  
  3223. <tr>
  3224. <td class="titledesc"><?php // _e('Image Dir Check','appthemes')?></td>
  3225. <td class="forminp">
  3226. <?php
  3227. // if (!is_dir(CP_UPLOAD_DIR)) {
  3228. // printf( '<font color="red">' . __('Image upload directory DOES NOT exist. Create a classipress folder in your %s folder.', 'appthemes'), WP_UPLOAD_DIR ) . '</font>';
  3229. // } else {
  3230. // echo '<font color="green">' . __('Image upload directory exists.','appthemes') . '</font>';
  3231. // }
  3232. ?>
  3233. </td>
  3234. </tr>
  3235.  
  3236. <tr>
  3237. <td class="titledesc"><?php // _e('Image Dir Writable','appthemes')?></td>
  3238. <td class="forminp">
  3239. <?php
  3240. // if (!is_writable(CP_UPLOAD_DIR)) {
  3241. // printf( '<font color="red">' . __('Image upload directory is NOT writable. Make sure you have the correct permissions set (CHMOD 777) on your %s folder.', 'appthemes'), CP_UPLOAD_DIR ) . '</font>';
  3242. // } else {
  3243. // echo '<font color="green">' . __('Image upload directory is writable.','appthemes') . '</font>';
  3244. // }
  3245. ?>
  3246. </td>
  3247. </tr>
  3248. -->
  3249.  
  3250. <thead>
  3251. <tr>
  3252. <th scope="col" width="200px"><?php _e('PayPal IPN Check','appthemes')?></th>
  3253. <th scope="col">&nbsp;</th>
  3254. </tr>
  3255. </thead>
  3256.  
  3257. <tr>
  3258. <td class="titledesc"><?php _e('FSOCKOPEN Check','appthemes')?></td>
  3259. <td class="forminp"><?php if ( function_exists('fsockopen') ) echo '<span style="color:green">' . __('Your server has fsockopen enabled.', 'appthemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not have fsockopen enabled so PayPal IPN will not work. Contact your host provider to have it enabled.', 'appthemes'). '</span>'; ?></td>
  3260. </tr>
  3261.  
  3262. <tr>
  3263. <td class="titledesc"><?php _e('OPENSSL Check','appthemes')?></td>
  3264. <td class="forminp"><?php if ( function_exists('openssl_open') ) echo '<span style="color:g
  3265. appthemesreen">' . __('Your server has openssl_open enabled. Also make sure port 443 is open on the firewall.', 'appthemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not have openssl_open enabled so PayPal IPN will not work. Contact your host provider to have it enabled.', 'appthemes'). '</span>'; ?></td>
  3266. </tr>
  3267.  
  3268. <?php if ( function_exists( 'wp_remote_post' ) ) : ?>
  3269. <tr>
  3270. <td class="titledesc"><?php _e('WP Remote Post Check','appthemes')?></td>
  3271. <td class="forminp"><?php
  3272. $paypal_adr = 'https://www.paypal.com/cgi-bin/webscr';
  3273. $params = array(
  3274. 'timeout' => 10
  3275. );
  3276. $response = wp_remote_post( $paypal_adr, $params );
  3277.  
  3278. // Retry
  3279. if ( is_wp_error($response) ) {
  3280. $params['sslverify'] = false;
  3281. $response = wp_remote_post( $paypal_adr, $params );
  3282. }
  3283.  
  3284. if ( !is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) echo '<span style="color:green">' . __('The wp_remote_post() test to PayPal was successful.', 'appthemes'). '</span>'; else echo '<span style="color:red">' . __('The wp_remote_post() test to PayPal failed. Sorry, PayPal IPN won\'t work with your server.', 'appthemes'). '</span>';
  3285. ?></td>
  3286. </tr>
  3287. <?php endif; ?>
  3288.  
  3289. <thead>
  3290. <tr>
  3291. <th scope="col" width="200px"><?php _e('Other Checks','appthemes')?></th>
  3292. <th scope="col">&nbsp;</th>
  3293. </tr>
  3294. </thead>
  3295.  
  3296. <tr>
  3297. <td class="titledesc"><?php _e('CURL Check','appthemes')?></td>
  3298. <td class="forminp"><?php if ( function_exists('curl_init') ) echo '<span style="color:green">' . __('Your server has curl enabled.', 'appthemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not have curl enabled so some functions will not work. Contact your host provider to have it enabled.', 'appthemes'). '</span>'; ?></td>
  3299. </tr>
  3300.  
  3301. <tr>
  3302. <td class="titledesc"><?php _e('JSON DECODE Check','appthemes')?></td>
  3303. <td class="forminp"><?php if ( function_exists('json_decode') ) echo '<span style="color:green">' . __('Your server has json_decode enabled.', 'appthemes'). '</span>'; else echo '<span style="color:red">' . __('Your server does not have json_decode enabled so some functions will not work. Contact your host provider to have it enabled.', 'appthemes'). '</span>'; ?></td>
  3304. </tr>
  3305.  
  3306.  
  3307. </tbody>
  3308.  
  3309. </table>
  3310.  
  3311. </div> <!-- # tab0 -->
  3312.  
  3313. <div id="tab1">
  3314.  
  3315. <table class="widefat fixed" style="width:850px;">
  3316. <thead>
  3317. <tr>
  3318. <th scope="col"><?php _e('Next Run Date','appthemes')?></th>
  3319. <th scope="col"><?php _e('Frequency','appthemes')?></th>
  3320. <th scope="col"><?php _e('Hook Name','appthemes')?></th>
  3321. </tr>
  3322. </thead>
  3323. <tbody>
  3324. <?php
  3325. $cron = _get_cron_array();
  3326. $schedules = wp_get_schedules();
  3327. $date_format = _x( 'M j, Y @ G:i','appthemes');
  3328. foreach ( $cron as $timestamp => $cronhooks ) {
  3329. foreach ( (array) $cronhooks as $hook => $events ) {
  3330. foreach ( (array) $events as $key => $event ) {
  3331. $cron[ $timestamp ][ $hook ][ $key ][ 'date' ] = date_i18n( $date_format, $timestamp );
  3332. }
  3333. }
  3334. }
  3335. ?>
  3336. <?php foreach ( $cron as $timestamp => $cronhooks ) { ?>
  3337. <?php foreach ( (array) $cronhooks as $hook => $events ) { ?>
  3338. <?php foreach ( (array) $events as $event ) { ?>
  3339. <tr>
  3340. <th scope="row"><?php echo $event[ 'date' ]; ?></th>
  3341. <td>
  3342. <?php
  3343. if ( $event[ 'schedule' ] ) {
  3344. echo $schedules [ $event[ 'schedule' ] ][ 'display' ];
  3345. } else {
  3346. ?><em><?php _e('One-off event','appthemes')?></em><?php
  3347. }
  3348. ?>
  3349. </td>
  3350. <td><?php echo $hook; ?></td>
  3351. </tr>
  3352. <?php } ?>
  3353. <?php } ?>
  3354. <?php } ?>
  3355. </tbody>
  3356. </table>
  3357.  
  3358. </div> <!-- # tab1 -->
  3359.  
  3360. <div id="tab2">
  3361.  
  3362. <table class="widefat fixed" style="width:850px;">
  3363.  
  3364.  
  3365. <thead>
  3366. <tr>
  3367. <th scope="col" width="200px"><?php _e('Theme Cache','appthemes')?></th>
  3368. <th scope="col">&nbsp;</th>
  3369. </tr>
  3370. </thead>
  3371.  
  3372. <form method="post" id="mainform" action="">
  3373. <tr>
  3374. <td class="titledesc"><?php _e('Flush Theme Cache','appthemes')?></td>
  3375. <td class="forminp">
  3376. <p class="submit"><input name="save" type="submit" value="<?php _e('Flush Entire ClassiPress Cache','appthemes') ?>" /><br />
  3377. <?php _e("Sometimes you may have changed something and it hasn't been updated on your site. Flushing the cache will empty anything that ClassiPress has stored in the cache (i.e. category drop-down menu, home page directory structure, etc).",'appthemes')?>
  3378. </p>
  3379. <input name="flushcache" type="hidden" value="yes" />
  3380. </td>
  3381. </tr>
  3382. </form>
  3383.  
  3384. <thead>
  3385. <tr>
  3386. <th scope="col" width="200px"><?php _e('Uninstall Theme','appthemes')?></th>
  3387. <th scope="col">&nbsp;</th>
  3388. </tr>
  3389. </thead>
  3390.  
  3391. <form method="post" id="mainform" action="">
  3392. <tr>
  3393. <td class="titledesc"><?php _e('Delete Database Tables','appthemes')?></td>
  3394. <td class="forminp">
  3395. <p class="submit"><input onclick="return confirmBeforeDeleteTbls();" name="save" type="submit" value="<?php _e('Delete ClassiPress Database Tables','appthemes') ?>" /><br />
  3396. <?php _e('Do you wish to completely delete all ClassiPress database tables? Once you do this you will lose any custom fields, forms, ad packs, etc that you have created.','appthemes')?>
  3397. </p>
  3398. <input name="deletetables" type="hidden" value="yes" />
  3399. </td>
  3400. </tr>
  3401. </form>
  3402.  
  3403. <form method="post" id="mainform" action="">
  3404. <tr>
  3405. <td class="titledesc"><?php _e('Delete Config Options','appthemes')?></td>
  3406. <td class="forminp">
  3407. <p class="submit"><input onclick="return confirmBeforeDeleteOptions();" name="save" type="submit" value="<?php _e('Delete ClassiPress Config Options','appthemes') ?>" /><br />
  3408. <?php _e('Do you wish to completely delete all ClassiPress configuration options? This will delete all values saved on the settings, pricing, gateways, etc admin pages from the wp_options database table.','appthemes')?>
  3409. </p>
  3410. <input name="deleteoptions" type="hidden" value="yes" />
  3411. </td>
  3412. </tr>
  3413. </form>
  3414.  
  3415. <thead>
  3416. <tr>
  3417. <th scope="col" width="200px"><?php _e('Theme','appthemes')?></th>
  3418. <th scope="col">&nbsp;</th>
  3419. </tr>
  3420. </thead>
  3421. <!--
  3422. <tr>
  3423. <td class="titledesc"><?php _e('Rerun Install Script','appthemes')?></td>
  3424. <td class="forminp">
  3425. <form action="?page=sysinfo&reinstall=yes" id="reinstall-form" method="post">
  3426. <p class="submit btop">
  3427. <input type="submit" value="<?php _e('Reinstall ClassiPress','appthemes')?>" name="convert" onclick="return confirmUpdate();" /><br />
  3428. <?php _e("Any website administrators that are developeres may have a desire to run the install script again. This is the same thing that occurs when you move between ClassiPress versions and click to update your database version.",'appthemes')?>
  3429. </p>
  3430. <input type="hidden" value="resintall" name="submitted" />
  3431. </form>
  3432. </td>
  3433. </tr>
  3434. -->
  3435. <tr>
  3436. <td class="titledesc"><?php _e('Rerun Migration Script','appthemes')?></td>
  3437. <td class="forminp">
  3438. <form action="admin.php?page=settings" id="reinstall-form" method="post">
  3439. <p class="submit btop">
  3440. <input type="submit" value="<?php _e('Rerun ClassiPress Migration Script','appthemes')?>" name="migrate" /><br />
  3441. <?php _e("If you're still using ClassiPress version 3.0.4 (or earlier) and were not prompted to upgrade to 3.0.5 or the script timed out, click this button. It will attempt to rerun the migration script again. Running this script won't do any harm if you aren't sure about it.",'appthemes'); ?> <br /><br />
  3442. </p>
  3443. <input type="hidden" value="convertToCustomPostType" name="submitted" />
  3444. </form>
  3445. </td>
  3446. </tr>
  3447.  
  3448.  
  3449.  
  3450.  
  3451. </table>
  3452.  
  3453. </div> <!-- # tab2 -->
  3454.  
  3455. </div><!-- #tab-wrap -->
  3456.  
  3457.  
  3458. </div>
  3459.  
  3460. <script type="text/javascript">
  3461. /* <![CDATA[ */
  3462. function confirmBeforeDeleteTbls() { return confirm("<?php _e('WARNING: You are about to completely delete all ClassiPress database tables. Are you sure you want to proceed? (This cannot be undone)', 'appthemes'); ?>"); }
  3463. function confirmBeforeDeleteOptions() { return confirm("<?php _e('WARNING: You are about to completely delete all ClassiPress configuration options from the wp_options database table. Are you sure you want to proceed? (This cannot be undone)', 'appthemes'); ?>"); }
  3464. /* ]]> */
  3465. </script>
  3466.  
  3467. <?php
  3468. }
  3469.  
  3470.  
  3471. ?>
  3472. /span
  3473. /th
Advertisement
Add Comment
Please, Sign In to add comment