PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/simple-ads-manager/list.admin.class.php

https://github.com/markkevans/simple-ads-manager
PHP | 493 lines | 469 code | 13 blank | 11 comment | 65 complexity | 7667fac9c62dd4cd7f58d29ff93f58bf MD5 | raw file
  1. <?php
  2. if(!class_exists('SamPlaceList')) {
  3. class SamPlaceList {
  4. private $settings = array();
  5. public function __construct($settings) {
  6. $this->settings = $settings;
  7. }
  8. /**
  9. * Outputs the name of Ads Place Size.
  10. *
  11. * Returns full Ads Place Size name.
  12. *
  13. * @since 0.1.1
  14. *
  15. * @param string $size Short name of Ads Place size
  16. * @return string value of Ads Place Size Name
  17. */
  18. private function getAdSize($value = '', $width = null, $height = null) {
  19. if($value == '') return null;
  20. if($value == 'custom') return array('name' => __('Custom sizes', SAM_DOMAIN), 'width' => $width, 'height' => $height);
  21. $aSizes = array(
  22. '800x90' => sprintf('%1$s x %2$s %3$s', 800, 90, __('Large Leaderboard', SAM_DOMAIN)),
  23. '728x90' => sprintf('%1$s x %2$s %3$s', 728, 90, __('Leaderboard', SAM_DOMAIN)),
  24. '600x90' => sprintf('%1$s x %2$s %3$s', 600, 90, __('Small Leaderboard', SAM_DOMAIN)),
  25. '550x250' => sprintf('%1$s x %2$s %3$s', 550, 250, __('Mega Unit', SAM_DOMAIN)),
  26. '550x120' => sprintf('%1$s x %2$s %3$s', 550, 120, __('Small Leaderboard', SAM_DOMAIN)),
  27. '550x90' => sprintf('%1$s x %2$s %3$s', 550, 90, __('Small Leaderboard', SAM_DOMAIN)),
  28. '468x180' => sprintf('%1$s x %2$s %3$s', 468, 180, __('Tall Banner', SAM_DOMAIN)),
  29. '468x120' => sprintf('%1$s x %2$s %3$s', 468, 120, __('Tall Banner', SAM_DOMAIN)),
  30. '468x90' => sprintf('%1$s x %2$s %3$s', 468, 90, __('Tall Banner', SAM_DOMAIN)),
  31. '468x60' => sprintf('%1$s x %2$s %3$s', 468, 60, __('Banner', SAM_DOMAIN)),
  32. '450x90' => sprintf('%1$s x %2$s %3$s', 450, 90, __('Tall Banner', SAM_DOMAIN)),
  33. '430x90' => sprintf('%1$s x %2$s %3$s', 430, 90, __('Tall Banner', SAM_DOMAIN)),
  34. '400x90' => sprintf('%1$s x %2$s %3$s', 400, 90, __('Tall Banner', SAM_DOMAIN)),
  35. '234x60' => sprintf('%1$s x %2$s %3$s', 234, 60, __('Half Banner', SAM_DOMAIN)),
  36. '200x90' => sprintf('%1$s x %2$s %3$s', 200, 90, __('Tall Half Banner', SAM_DOMAIN)),
  37. '150x50' => sprintf('%1$s x %2$s %3$s', 150, 50, __('Half Banner', SAM_DOMAIN)),
  38. '120x90' => sprintf('%1$s x %2$s %3$s', 120, 90, __('Button', SAM_DOMAIN)),
  39. '120x60' => sprintf('%1$s x %2$s %3$s', 120, 60, __('Button', SAM_DOMAIN)),
  40. '83x31' => sprintf('%1$s x %2$s %3$s', 83, 31, __('Micro Bar', SAM_DOMAIN)),
  41. '728x15x4' => sprintf('%1$s x %2$s %3$s, %4$s', 728, 15, __('Thin Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  42. '728x15x5' => sprintf('%1$s x %2$s %3$s, %4$s', 728, 15, __('Thin Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5)),
  43. '468x15x4' => sprintf('%1$s x %2$s %3$s, %4$s', 468, 15, __('Thin Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  44. '468x15x5' => sprintf('%1$s x %2$s %3$s, %4$s', 468, 15, __('Thin Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5)),
  45. '160x600' => sprintf('%1$s x %2$s %3$s', 160, 600, __('Wide Skyscraper', SAM_DOMAIN)),
  46. '120x600' => sprintf('%1$s x %2$s %3$s', 120, 600, __('Skyscraper', SAM_DOMAIN)),
  47. '200x360' => sprintf('%1$s x %2$s %3$s', 200, 360, __('Wide Half Banner', SAM_DOMAIN)),
  48. '240x400' => sprintf('%1$s x %2$s %3$s', 240, 400, __('Vertical Rectangle', SAM_DOMAIN)),
  49. '180x300' => sprintf('%1$s x %2$s %3$s', 180, 300, __('Tall Rectangle', SAM_DOMAIN)),
  50. '200x270' => sprintf('%1$s x %2$s %3$s', 200, 270, __('Tall Rectangle', SAM_DOMAIN)),
  51. '120x240' => sprintf('%1$s x %2$s %3$s', 120, 240, __('Vertical Banner', SAM_DOMAIN)),
  52. '336x280' => sprintf('%1$s x %2$s %3$s', 336, 280, __('Large Rectangle', SAM_DOMAIN)),
  53. '336x160' => sprintf('%1$s x %2$s %3$s', 336, 160, __('Wide Rectangle', SAM_DOMAIN)),
  54. '334x100' => sprintf('%1$s x %2$s %3$s', 334, 100, __('Wide Rectangle', SAM_DOMAIN)),
  55. '300x250' => sprintf('%1$s x %2$s %3$s', 300, 250, __('Medium Rectangle', SAM_DOMAIN)),
  56. '300x150' => sprintf('%1$s x %2$s %3$s', 300, 150, __('Small Wide Rectangle', SAM_DOMAIN)),
  57. '300x125' => sprintf('%1$s x %2$s %3$s', 300, 125, __('Small Wide Rectangle', SAM_DOMAIN)),
  58. '300x70' => sprintf('%1$s x %2$s %3$s', 300, 70, __('Mini Wide Rectangle', SAM_DOMAIN)),
  59. '250x250' => sprintf('%1$s x %2$s %3$s', 250, 250, __('Square', SAM_DOMAIN)),
  60. '200x200' => sprintf('%1$s x %2$s %3$s', 200, 200, __('Small Square', SAM_DOMAIN)),
  61. '200x180' => sprintf('%1$s x %2$s %3$s', 200, 180, __('Small Rectangle', SAM_DOMAIN)),
  62. '180x150' => sprintf('%1$s x %2$s %3$s', 180, 150, __('Small Rectangle', SAM_DOMAIN)),
  63. '160x160' => sprintf('%1$s x %2$s %3$s', 160, 160, __('Small Square', SAM_DOMAIN)),
  64. '125x125' => sprintf('%1$s x %2$s %3$s', 125, 125, __('Button', SAM_DOMAIN)),
  65. '200x90x4' => sprintf('%1$s x %2$s %3$s, %4$s', 200, 90, __('Tall Half Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  66. '200x90x5' => sprintf('%1$s x %2$s %3$s, %4$s', 200, 90, __('Tall Half Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5)),
  67. '180x90x4' => sprintf('%1$s x %2$s %3$s, %4$s', 180, 90, __('Half Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  68. '180x90x5' => sprintf('%1$s x %2$s %3$s, %4$s', 180, 90, __('Half Banner', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5)),
  69. '160x90x4' => sprintf('%1$s x %2$s %3$s, %4$s', 160, 90, __('Tall Button', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  70. '160x90x5' => sprintf('%1$s x %2$s %3$s, %4$s', 160, 90, __('Tall Button', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5)),
  71. '120x90x4' => sprintf('%1$s x %2$s %3$s, %4$s', 120, 90, __('Button', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 4, SAM_DOMAIN), 4)),
  72. '120x90x5' => sprintf('%1$s x %2$s %3$s, %4$s', 120, 90, __('Button', SAM_DOMAIN), sprintf(_n('%d Link', '%d Links', 5, SAM_DOMAIN), 5))
  73. );
  74. $aSize = explode("x", $value);
  75. //$aSize = preg_split("[x]", $value, null, PREG_SPLIT_NO_EMPTY);
  76. return array('name' => $aSizes[$value], 'width' => $aSize[0], 'height' => $aSize[1]);
  77. }
  78. public function page() {
  79. global $wpdb;
  80. $pTable = $wpdb->prefix . "sam_places";
  81. $aTable = $wpdb->prefix . "sam_ads";
  82. if(isset($_GET['mode'])) $mode = $_GET['mode'];
  83. else $mode = 'active';
  84. if(isset($_GET["action"])) $action = $_GET['action'];
  85. else $action = 'places';
  86. if(isset($_GET['item'])) $item = $_GET['item'];
  87. else $item = null;
  88. if(isset($_GET['iaction'])) $iaction = $_GET['iaction'];
  89. else $iaction = null;
  90. if(isset($_GET['iitem'])) $iitem = $_GET['iitem'];
  91. else $iitem = null;
  92. if(isset($_GET['apage'])) $apage = abs( (int) $_GET['apage'] );
  93. else $apage = 1;
  94. $options = $this->settings;
  95. $places_per_page = $options['placesPerPage'];
  96. $items_per_page = $options['itemsPerPage'];
  97. switch($action) {
  98. case 'places':
  99. if(!is_null($item)) {
  100. if($iaction === 'delete') $wpdb->update( $pTable, array( 'trash' => true ), array( 'id' => $item ), array( '%d' ), array( '%d' ) );
  101. elseif($iaction === 'untrash') $wpdb->update( $pTable, array( 'trash' => false ), array( 'id' => $item ), array( '%d' ), array( '%d' ) );
  102. elseif($iaction === 'kill') $wpdb->query("DELETE FROM {$pTable} WHERE id={$item}");
  103. }
  104. if($iaction === 'kill-em-all') $wpdb->query("DELETE FROM {$pTable} WHERE trash=true");
  105. if($iaction === 'clear-stats') {
  106. $wpdb->query("UPDATE $pTable SET $pTable.patch_hits = 0;");
  107. $wpdb->query("UPDATE $aTable SET $aTable.ad_hits = 0, $aTable.ad_clicks = 0;");
  108. }
  109. $trash_num = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM '.$pTable.' WHERE trash = TRUE'));
  110. $active_num = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM '.$pTable.' WHERE trash = FALSE'));
  111. if(is_null($active_num)) $active_num = 0;
  112. if(is_null($trash_num)) $trash_num = 0;
  113. $all_num = $trash_num + $active_num;
  114. $total = (($mode !== 'all') ? (($mode === 'trash') ? $trash_num : $active_num) : $all_num);
  115. $start = $offset = ( $apage - 1 ) * $places_per_page;
  116. $page_links = paginate_links( array(
  117. 'base' => add_query_arg( 'apage', '%#%' ),
  118. 'format' => '',
  119. 'prev_text' => __('&laquo;'),
  120. 'next_text' => __('&raquo;'),
  121. 'total' => ceil($total / $places_per_page),
  122. 'current' => $apage
  123. ));
  124. ?>
  125. <div class='wrap'>
  126. <div class="icon32" style="background: url('<?php echo SAM_IMG_URL.'sam-list.png' ?>') no-repeat transparent; "><br/></div>
  127. <h2><?php _e('Managing Ads Places', SAM_DOMAIN); ?></h2>
  128. <?php
  129. include_once('errors.class.php');
  130. $errors = new samErrors();
  131. if(!empty($errors->errorString)) echo $errors->errorString;
  132. ?>
  133. <ul class="subsubsub">
  134. <li><a <?php if($mode === 'all') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=all"><?php _e('All', SAM_DOMAIN); ?></a> (<?php echo $all_num; ?>) | </li>
  135. <li><a <?php if($mode === 'active') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=active"><?php _e('Active', SAM_DOMAIN); ?></a> (<?php echo $active_num; ?>) | </li>
  136. <li><a <?php if($mode === 'trash') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=trash"><?php _e('Trash', SAM_DOMAIN); ?></a> (<?php echo $trash_num; ?>)</li>
  137. </ul>
  138. <div class="tablenav">
  139. <div class="alignleft">
  140. <?php if($mode === 'trash') {?>
  141. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=trash&iaction=kill-em-all"><?php _e('Clear Trash', SAM_DOMAIN); ?></a>
  142. <?php } else { ?>
  143. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=new&mode=place"><?php _e('Add New Place', SAM_DOMAIN); ?></a>
  144. <?php } ?>
  145. </div>
  146. <div class='alignleft'>
  147. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=<?php echo $mode; ?>&iaction=clear-stats"><?php _e('Reset Statistics', SAM_DOMAIN); ?></a>
  148. </div>
  149. <div class="tablenav-pages">
  150. <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s', SAM_DOMAIN ) . '</span>%s',
  151. number_format_i18n( $start + 1 ),
  152. number_format_i18n( min( $apage * $places_per_page, $total ) ),
  153. '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
  154. $page_links
  155. ); echo $page_links_text; ?>
  156. </div>
  157. </div>
  158. <div class="clear"></div>
  159. <table class="widefat fixed" cellpadding="0">
  160. <thead>
  161. <tr>
  162. <th id="t-idg" class="manage-column column-title" style="width:5%;" scope="col"><?php _e('ID', SAM_DOMAIN); ?></th>
  163. <th id="t-name" class="manage-column column-title" style="width:31%;" scope="col"><?php _e('Place Name', SAM_DOMAIN);?></th>
  164. <th id="t-size" class="manage-column column-title" style="width:15%;" scope="col"><?php _e('Size', SAM_DOMAIN); ?></th>
  165. <th id="t-size" class="manage-column column-title" style="width:7%;" scope="col"><?php _e('Hits', SAM_DOMAIN); ?></th>
  166. <th id="t-size" class="manage-column column-title" style="width:7%;" scope="col"><?php _e('Total Hits', SAM_DOMAIN); ?></th>
  167. <th id="tp-items" class="manage-column column-title" style="width:10%;" scope="col"><div class="vers"><?php _e('Total Ads', SAM_DOMAIN); ?></div></th>
  168. <th id="tp-earnings" class="manage-column column-title" style="width:15%;" scope="col"><?php _e('Earnings', SAM_DOMAIN); ?></th>
  169. </tr>
  170. </thead>
  171. <tfoot>
  172. <tr>
  173. <th id="b-idg" class="manage-column column-title" style="width:5%;" scope="col"><?php _e('ID', SAM_DOMAIN); ?></th>
  174. <th id="b-name" class="manage-column column-title" style="width:31%;" scope="col"><?php _e('Place Name', SAM_DOMAIN);?></th>
  175. <th id="b-size" class="manage-column column-title" style="width:15%;" scope="col"><?php _e('Size', SAM_DOMAIN); ?></th>
  176. <th id="t-size" class="manage-column column-title" style="width:7%;" scope="col"><?php _e('Hits', SAM_DOMAIN); ?></th>
  177. <th id="t-size" class="manage-column column-title" style="width:7%;" scope="col"><?php _e('Total Hits', SAM_DOMAIN); ?></th>
  178. <th id="bp-items" class="manage-column column-title" style="width:10%;" scope="col"><div class="vers"><?php _e('Total Ads', SAM_DOMAIN); ?></div></th>
  179. <th id="bp-earnings" class="manage-column column-title" style="width:15%;" scope="col"><?php _e('Earnings', SAM_DOMAIN); ?></th>
  180. </tr>
  181. </tfoot>
  182. <tbody>
  183. <?php
  184. $pSql = "SELECT
  185. $pTable.id,
  186. $pTable.name,
  187. $pTable.description,
  188. $pTable.place_size,
  189. $pTable.place_custom_width,
  190. $pTable.place_custom_height,
  191. $pTable.patch_hits,
  192. (IFNULL((SELECT sum($aTable.ad_hits) FROM $aTable WHERE $aTable.pid = $pTable.id), 0) + $pTable.patch_hits) as total_ad_hits,
  193. (IFNULL((SELECT SUM(IF(cpm > 0, ad_hits*cpm/1000, 0)) FROM $aTable WHERE $aTable.pid = $pTable.id), 0)) AS e_cpm,
  194. (IFNULL((SELECT SUM(IF(cpc > 0, ad_clicks*cpc, 0)) FROM $aTable WHERE $aTable.pid = $pTable.id), 0)) AS e_cpc,
  195. (IFNULL((SELECT SUM(IF(ad_schedule AND per_month > 0, DATEDIFF(CURDATE(), ad_start_date)*per_month/30, 0)) FROM $aTable WHERE $aTable.pid = $pTable.id), 0)) AS e_month,
  196. $pTable.trash,
  197. (SELECT COUNT(*) FROM $aTable WHERE $aTable.pid = $pTable.id) AS items
  198. FROM $pTable".
  199. (($mode !== 'all') ? " WHERE $pTable.trash = ".(($mode === 'trash') ? 'TRUE' : 'FALSE') : '').
  200. " LIMIT $offset, $places_per_page";
  201. $places = $wpdb->get_results($pSql, ARRAY_A);
  202. $i = 0;
  203. if(!is_array($places) || empty ($places)) {
  204. ?>
  205. <tr class="no-items">
  206. <th class="colspanchange" colspan='7'><?php _e('There are no data ...', SAM_DOMAIN).$pTable; ?></th>
  207. </tr>
  208. <?php } else {
  209. switch($options['currency']) {
  210. case 'auto': $lang = str_replace('-', '_', get_bloginfo('language')); break;
  211. case 'usd' : $lang = 'en_US'; break;
  212. case 'euro': $lang = 'de_DE'; break;
  213. default: $lang = str_replace('-', '_', get_bloginfo('language'));
  214. }
  215. $codeset = get_bloginfo('charset');
  216. setlocale(LC_MONETARY, $lang.'.'.$codeset);
  217. foreach($places as $row) {
  218. $apSize = $this->getAdSize($row['place_size'], $row['place_custom_width'], $row['place_custom_height']);
  219. $eMonth = round(floatval($row['e_month']), 2);
  220. $eCPM = round(floatval($row['e_cpm']), 2);
  221. $eCPC = round(floatval($row['e_cpc']), 2);
  222. $eTotal = $eMonth + $eCPC + $eCPM;
  223. $earnings = $eMonth ? __('Placement', SAM_DOMAIN).": ".money_format('%.2n', $eMonth)." <br/>" : '';
  224. $earnings .= $eCPM ? __('Hits', SAM_DOMAIN).": ".money_format('%.2n', $eCPM)." <br/>" : '';
  225. $earnings .= $eCPC ? __('Clicks', SAM_DOMAIN).": ".money_format('%.2n', $eCPC)." <br/>" : '';
  226. $earnings .= $eTotal ? "<strong>".__('Total', SAM_DOMAIN).": ".money_format('%.2n', $eTotal)." </strong>" : __('N/A', SAM_DOMAIN);
  227. ?>
  228. <tr id="<?php echo $row['id'];?>" class="<?php echo (($i & 1) ? 'alternate' : ''); ?> author-self status-publish iedit" valign="top">
  229. <th class="post-title column-title"><?php echo $row['id']; ?></th>
  230. <td class="post-title column-title">
  231. <strong style='display: inline;'><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=active&item=<?php echo $row['id']; ?>"><?php echo $row['name'];?></a><?php echo ((($row['trash'] == true) && ($mode === 'all')) ? '<span class="post-state"> - '.__('in Trash', SAM_DOMAIN).'</span>' : ''); ?></strong><br/><?php echo $row['description'];?>
  232. <div class="row-actions">
  233. <span class="edit"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=edit&mode=place&item=<?php echo $row['id'] ?>" title="<?php _e('Edit Place', SAM_DOMAIN) ?>"><?php _e('Edit', SAM_DOMAIN); ?></a> | </span>
  234. <?php
  235. if($row['trash'] == true) {
  236. ?>
  237. <span class="untrash"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=<?php echo $mode ?>&iaction=untrash&item=<?php echo $row['id'] ?>" title="<?php _e('Restore this Place from the Trash', SAM_DOMAIN) ?>"><?php _e('Restore', SAM_DOMAIN); ?></a> | </span>
  238. <span class="delete"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=<?php echo $mode ?>&iaction=kill&item=<?php echo $row['id'] ?>" title="<?php _e('Remove this Place permanently', SAM_DOMAIN) ?>"><?php _e('Remove permanently', SAM_DOMAIN); ?></a></span>
  239. <?php
  240. }
  241. else {
  242. ?>
  243. <span class="delete"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=<?php echo $mode ?>&iaction=delete&item=<?php echo $row['id'] ?>" title="<?php _e('Move this Place to the Trash', SAM_DOMAIN) ?>"><?php _e('Delete', SAM_DOMAIN); ?></a> | </span>
  244. <span class="edit"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=active&item=<?php echo $row['id']; ?>" title="<?php _e('View List of Place Ads', SAM_DOMAIN) ?>"><?php _e('View Ads', SAM_DOMAIN); ?></a> | </span>
  245. <span class="edit"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=new&mode=item&place=<?php echo $row['id']; ?>" title="<?php _e('Create New Ad', SAM_DOMAIN) ?>"><?php _e('New Ad', SAM_DOMAIN); ?></a></span>
  246. <?php } ?>
  247. </div>
  248. </td>
  249. <td class="post-title column-title"><?php echo $apSize['name']; ?></td>
  250. <td class="post-title column-title"><div class="post-com-count-wrapper" style="text-align: center;"><?php echo $row['patch_hits'];?></div></td>
  251. <td class="post-title column-title"><div class="post-com-count-wrapper" style="text-align: center;"><?php echo $row['total_ad_hits'];?></div></td>
  252. <td class="post-title column-title"><div class="post-com-count-wrapper" style="text-align: center;"><?php echo $row['items'];?></div></td>
  253. <td class="post-title column-title"><div class='sam-earnings'><?php echo $earnings;?></div></td>
  254. </tr>
  255. <?php $i++; }}?>
  256. </tbody>
  257. </table>
  258. <div class="tablenav">
  259. <div class="alignleft">
  260. <?php if($mode === 'trash') {?>
  261. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=trash&iaction=kill-em-all"><?php _e('Clear Trash', SAM_DOMAIN); ?></a>
  262. <?php } else { ?>
  263. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=new&mode=place"><?php _e('Add New Place', SAM_DOMAIN); ?></a>
  264. <?php } ?>
  265. </div>
  266. <div class='alignleft'>
  267. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=places&mode=<?php echo $mode; ?>&iaction=clear-stats"><?php _e('Reset Statistics', SAM_DOMAIN); ?></a>
  268. </div>
  269. <div class="tablenav-pages">
  270. <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s', SAM_DOMAIN ) . '</span>%s',
  271. number_format_i18n( $start + 1 ),
  272. number_format_i18n( min( $apage * $places_per_page, $total ) ),
  273. '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
  274. $page_links
  275. ); echo $page_links_text; ?>
  276. </div>
  277. </div>
  278. </div>
  279. <?php
  280. break;
  281. case 'items':
  282. if(!is_null($item)) {
  283. if($iaction === 'delete') $wpdb->update( $aTable, array( 'trash' => true ), array( 'id' => $iitem ), array( '%d' ), array( '%d' ) );
  284. elseif($iaction === 'untrash') $wpdb->update( $aTable, array( 'trash' => false ), array( 'id' => $iitem ), array( '%d' ), array( '%d' ) );
  285. elseif($iaction === 'kill') $wpdb->query("DELETE FROM $aTable WHERE id = $iitem");
  286. }
  287. if($iaction === 'kill-em-all') $wpdb->query("DELETE FROM $aTable WHERE trash=true");
  288. $trash_num = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM '.$aTable.' WHERE (trash = TRUE) AND (pid = '.$item.')'));
  289. $active_num = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM '.$aTable.' WHERE (trash = FALSE) AND (pid = '.$item.')'));
  290. if(is_null($active_num)) $active_num = 0;
  291. if(is_null($trash_num)) $trash_num = 0;
  292. $all_num = $trash_num + $active_num;
  293. $places = $wpdb->get_row("SELECT id, name, trash FROM $pTable WHERE id = $item", ARRAY_A);
  294. $total = (($mode !== 'all') ? (($mode === 'trash') ? $trash_num : $active_num) : $all_num);
  295. $start = $offset = ( $apage - 1 ) * $items_per_page;
  296. $page_links = paginate_links( array(
  297. 'base' => add_query_arg( 'apage', '%#%' ),
  298. 'format' => '',
  299. 'prev_text' => __('&laquo;'),
  300. 'next_text' => __('&raquo;'),
  301. 'total' => ceil($total / $items_per_page),
  302. 'current' => $apage
  303. ));
  304. ?>
  305. <div class="wrap">
  306. <div class="icon32" style="background: url('<?php echo SAM_IMG_URL.'sam-list.png'; ?>') no-repeat transparent; "><br/></div>
  307. <h2><?php echo __('Managing Items of Ads Place', SAM_DOMAIN).' "'.$places['name'].'" ('.$item.') '; ?></h2>
  308. <?php
  309. include_once('errors.class.php');
  310. $errors = new samErrors();
  311. if(!empty($errors->errorString)) echo $errors->errorString;
  312. ?>
  313. <ul class="subsubsub">
  314. <li><a <?php if($mode === 'all') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=all&item=<?php echo $item ?>"><?php _e('All', SAM_DOMAIN); ?></a> (<?php echo $all_num; ?>) | </li>
  315. <li><a <?php if($mode === 'active') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=active&item=<?php echo $item ?>"><?php _e('Active', SAM_DOMAIN); ?></a> (<?php echo $active_num; ?>) | </li>
  316. <li><a <?php if($mode === 'trash') echo 'class="current"';?> href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=trash&item=<?php echo $item ?>"><?php _e('Trash', SAM_DOMAIN); ?></a> (<?php echo $trash_num; ?>)</li>
  317. </ul>
  318. <div class="tablenav">
  319. <div class="alignleft">
  320. <?php
  321. if($mode === 'trash') { ?>
  322. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=trash&iaction=kill-em-all&item=<?php echo $item ?>"><?php _e('Clear Trash', SAM_DOMAIN); ?></a>
  323. <?php } else { ?>
  324. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=new&mode=item&place=<?php echo $places['id']; ?>"><?php _e('Add New Ad', SAM_DOMAIN); ?></a>
  325. <?php } ?>
  326. </div>
  327. <div class="alignleft">
  328. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list"><?php _e('Back to Ads Places Management', SAM_DOMAIN); ?></a>
  329. </div>
  330. <div class="tablenav-pages">
  331. <?php
  332. $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s', SAM_DOMAIN ) . '</span>%s',
  333. number_format_i18n( $start + 1 ),
  334. number_format_i18n( min( $apage * $items_per_page, $total ) ),
  335. '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
  336. $page_links
  337. );
  338. echo $page_links_text;
  339. ?>
  340. </div>
  341. </div>
  342. <div class="clear"></div>
  343. <table class="widefat fixed" cellpadding="0">
  344. <thead>
  345. <tr>
  346. <th id="t-id" class="manage-column column-title" style="width:5%;" scope="col"><?php _e('ID', SAM_DOMAIN); ?></th>
  347. <th id="t-ad" class='manage-column column-title' style="width:55%;" scope="col"><?php _e('Advertisement', SAM_DOMAIN); ?></th>
  348. <th id="t-act" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Activity', SAM_DOMAIN);?></th>
  349. <th id="t-hits" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Hits', SAM_DOMAIN);?></th>
  350. <th id="t-clicks" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Clicks', SAM_DOMAIN);?></th>
  351. <th id="t-earnings" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Earnings', SAM_DOMAIN);?></th>
  352. </tr>
  353. </thead>
  354. <tfoot>
  355. <tr>
  356. <th id="b-id" class="manage-column column-title" style="width:5%;" scope="col"><?php _e('ID', SAM_DOMAIN); ?></th>
  357. <th id="b-ad" class='manage-column column-title' style="width:55%;" scope="col"><?php _e('Advertisement', SAM_DOMAIN); ?></th>
  358. <th id="b-act" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Activity', SAM_DOMAIN);?></th>
  359. <th id="b-hits" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Hits', SAM_DOMAIN);?></th>
  360. <th id="b-clicks" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Clicks', SAM_DOMAIN);?></th>
  361. <th id="b-earnings" class="manage-column column-title" style="width:10%;" scope="col"><?php _e('Earnings', SAM_DOMAIN);?></th>
  362. </tr>
  363. </tfoot>
  364. <tbody>
  365. <?php
  366. if($mode !== 'all')
  367. $aSql = "SELECT
  368. id,
  369. pid,
  370. name,
  371. description,
  372. ad_hits,
  373. ad_clicks,
  374. ad_weight,
  375. (IF(ad_schedule AND per_month > 0, DATEDIFF(CURDATE(), ad_start_date)*per_month/30, 0)) AS e_month,
  376. (cpm * ad_hits / 1000) AS e_cpm,
  377. (cpc * ad_clicks) AS e_cpc,
  378. trash,
  379. IF(DATEDIFF($aTable.ad_end_date, NOW()) IS NULL OR DATEDIFF($aTable.ad_end_date, NOW()) > 0, FALSE, TRUE) AS expired
  380. FROM $aTable
  381. WHERE (pid = $item) AND (trash = ".(($mode === 'trash') ? 'TRUE' : 'FALSE').")
  382. LIMIT $offset, $items_per_page";
  383. else
  384. $aSql = "SELECT
  385. id,
  386. pid,
  387. name,
  388. description,
  389. ad_hits,
  390. ad_clicks,
  391. ad_weight,
  392. (IF(ad_schedule AND per_month > 0, DATEDIFF(CURDATE(), ad_start_date)*per_month/30, 0)) AS e_month,
  393. (cpm * ad_hits / 1000) AS e_cpm,
  394. (cpc * ad_clicks) AS e_cpc,
  395. trash,
  396. IF(DATEDIFF($aTable.ad_end_date, NOW()) IS NULL OR DATEDIFF($aTable.ad_end_date, NOW()) > 0, FALSE, TRUE) AS expired
  397. FROM $aTable
  398. WHERE pid = $item
  399. LIMIT $offset, $items_per_page";
  400. $items = $wpdb->get_results($aSql, ARRAY_A);
  401. $i = 0;
  402. if(!is_array($items) || empty($items)) {
  403. ?>
  404. <tr class="no-items" valign="top">
  405. <th class="colspanchange" colspan='6'><?php _e('There are no data ...', SAM_DOMAIN); ?></th>
  406. </tr>
  407. <?php
  408. }
  409. else {
  410. switch($options['currency']) {
  411. case 'auto': $lang = str_replace('-', '_', get_bloginfo('language')); break;
  412. case 'usd' : $lang = 'en_US'; break;
  413. case 'euro': $lang = 'de_DE'; break;
  414. default: $lang = str_replace('-', '_', get_bloginfo('language'));
  415. }
  416. $codeset = get_bloginfo('charset');
  417. setlocale(LC_MONETARY, $lang.'.'.$codeset);
  418. foreach($items as $row) {
  419. if($row['ad_weight'] > 0 && !$row['trash'] && !$row['expired']) $activity = __('Yes', SAM_DOMAIN);
  420. else $activity = __('No', SAM_DOMAIN);
  421. $eMonth = round(floatval($row['e_month']), 2);
  422. $eCPM = round(floatval($row['e_cpm']), 2);
  423. $eCPC = round(floatval($row['e_cpc']), 2);
  424. $eTotal = $eMonth + $eCPC + $eCPM;
  425. $earnings = $eMonth ? __('Placement', SAM_DOMAIN).": ".money_format('%.2n', $eMonth)." <br/>" : '';
  426. $earnings .= $eCPM ? __('Hits', SAM_DOMAIN).": ".money_format('%.2n', $eCPM)." <br/>" : '';
  427. $earnings .= $eCPC ? __('Clicks', SAM_DOMAIN).": ".money_format('%.2n', $eCPC)." <br/>" : '';
  428. $earnings .= $eTotal ? "<strong>".__('Total', SAM_DOMAIN).": ".money_format('%.2n', $eTotal)." </strong>" : __('N/A', SAM_DOMAIN);
  429. ?>
  430. <tr id="<?php echo $row['id'];?>" class="<?php echo (($i & 1) ? 'alternate' : ''); ?> author-self status-publish iedit" valign="top">
  431. <th class="post-title column-title"><?php echo $row['id']; ?></th>
  432. <td class="column-icon column-title">
  433. <strong><a href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=edit&mode=item&item=<?php echo $row['id']; ?>"><?php echo $row['name'];?></a><?php echo ((($row['trash'] == true) && ($mode === 'all')) ? '<span class="post-state"> - '.__('in Trash', SAM_DOMAIN).'</span>' : ''); ?></strong><br/><?php echo $row['description'];?>
  434. <div class="row-actions">
  435. <span class="edit"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=edit&mode=item&item=<?php echo $row['id'] ?>" title="<?php _e('Edit this Item of Ads Place', SAM_DOMAIN) ?>"><?php _e('Edit', SAM_DOMAIN); ?></a> | </span>
  436. <?php
  437. if($row['trash'] == true) {
  438. ?>
  439. <span class="untrash"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=<?php echo $mode ?>&iaction=untrash&item=<?php echo $row['pid'] ?>&iitem=<?php echo $row['id'] ?>" title="<?php _e('Restore this Ad from the Trash', SAM_DOMAIN) ?>"><?php _e('Restore', SAM_DOMAIN); ?></a> | </span>
  440. <span class="delete"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=<?php echo $mode ?>&iaction=kill&item=<?php echo $row['pid'] ?>&iitem=<?php echo $row['id'] ?>" title="<?php _e('Remove this Ad permanently', SAM_DOMAIN) ?>"><?php _e('Remove permanently', SAM_DOMAIN); ?></a> </span>
  441. <?php } else { ?><span class="delete"><a href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=<?php echo $mode ?>&iaction=delete&item=<?php echo $row['pid'] ?>&iitem=<?php echo $row['id'] ?>" title="<?php _e('Move this item to the Trash', SAM_DOMAIN) ?>"><?php _e('Delete', SAM_DOMAIN); ?></a> </span><?php } ?>
  442. </div>
  443. </td>
  444. <td class="post-title column-title"><?php echo $activity; ?></td>
  445. <td class="post-title column-title"><?php echo $row['ad_hits'];?></td>
  446. <td class="post-title column-title"><?php echo $row['ad_clicks'];?></td>
  447. <td class="post-title column-title"><div class='sam-earnings'><?php echo $earnings;?></div></td>
  448. </tr>
  449. <?php $i++; }}?>
  450. </tbody>
  451. </table>
  452. <div class="tablenav">
  453. <div class="alignleft">
  454. <?php
  455. if($mode === 'trash') { ?>
  456. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list&action=items&mode=trash&iaction=kill-em-all&item=<?php echo $item ?>"><?php _e('Clear Trash', SAM_DOMAIN); ?></a>
  457. <?php } else { ?>
  458. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-edit&action=new&mode=item&place=<?php echo $places['id']; ?>"><?php _e('Add New Ad', SAM_DOMAIN); ?></a>
  459. <?php } ?>
  460. </div>
  461. <div class="alignleft">
  462. <a class="button-secondary" href="<?php echo admin_url('admin.php'); ?>?page=sam-list"><?php _e('Back to Ads Places Management', SAM_DOMAIN); ?></a>
  463. </div>
  464. <div class="tablenav-pages">
  465. <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s', SAM_DOMAIN ) . '</span>%s',
  466. number_format_i18n( $start + 1 ),
  467. number_format_i18n( min( $apage * $items_per_page, $total ) ),
  468. '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
  469. $page_links
  470. ); echo $page_links_text; ?>
  471. </div>
  472. </div>
  473. </div>
  474. <?php
  475. break;
  476. }
  477. }
  478. }
  479. }
  480. ?>