PageRenderTime 81ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/setup/ppc_accounts.php

https://github.com/ClickBooth/XTracks
PHP | 291 lines | 219 code | 66 blank | 6 comment | 56 complexity | 3e28f2d298dc302c07d1518bc3135599 MD5 | raw file
  1. <? include_once($_SERVER['DOCUMENT_ROOT'] . '/xtracks-app/bootstrap.php');
  2. AUTH::require_user();
  3. if ($_GET['edit_ppc_account_id']) {
  4. $editing = true;
  5. }
  6. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  7. if (isset($_POST['ppc_network_name'])) {
  8. $ppc_network_name = trim($_POST['ppc_network_name']);
  9. if (empty($ppc_network_name)) { $error['ppc_network_name'] = '<div class="error">Type in the name the ppc network.</div>'; }
  10. if (!$error) {
  11. $mysql['ppc_network_name'] = mysql_real_escape_string($_POST['ppc_network_name']);
  12. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  13. $mysql['ppc_network_time'] = time();
  14. $ppc_network_sql = "INSERT INTO `202_ppc_networks`
  15. SET `user_id`='".$mysql['user_id']."',
  16. `ppc_network_name`='".$mysql['ppc_network_name']."',
  17. `ppc_network_time`='".$mysql['ppc_network_time']."'";
  18. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  19. $add_success = true;
  20. }
  21. }
  22. if (isset($_POST['ppc_network_id'])) {
  23. $ppc_account_name = trim($_POST['ppc_account_name']);
  24. if ($ppc_account_name == '') { $error['ppc_account_name'] = '<div class="error">What is the username for this account?</div>'; }
  25. $ppc_network_id = trim($_POST['ppc_network_id']);
  26. if ($ppc_network_id == '') { $error['ppc_network_id'] = '<div class="error">What is the PPC network is this account attached to?</div>'; }
  27. if (!$error) {
  28. //check to see if this user is the owner of the ppc network hes trying to add an account to
  29. $mysql['ppc_network_id'] = mysql_real_escape_string($_POST['ppc_network_id']);
  30. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  31. $ppc_network_sql = "SELECT COUNT(*) FROM `202_ppc_networks` WHERE `user_id`='".$mysql['user_id']."' AND `ppc_network_id`='".$mysql['ppc_network_id']."'";
  32. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  33. if (mysql_result($ppc_network_result,0,0) == 0 ) {
  34. $error['wrong_user'] = '<div class="error">You are not authorized to add an account to another users\' network</div>';
  35. }
  36. }
  37. if (!$error) {
  38. //if editing, check to make sure the own the ppc account they are editing
  39. if ($editing == true) {
  40. $mysql['ppc_account_id'] = mysql_real_escape_string($_GET['edit_ppc_account_id']);
  41. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  42. $ppc_account_sql = "SELECT COUNT(*) FROM `202_ppc_accounts` WHERE `user_id`='".$mysql['user_id']."' AND `ppc_account_id`='".$mysql['ppc_account_id']."'";
  43. $ppc_account_result = _mysql_query($ppc_account_sql) ; //($ppc_account_sql);
  44. if (mysql_result($ppc_account_result,0,0) == 0 ) {
  45. $error['wrong_user'] .= '<div class="error">You are not authorized to modify another users ppc account</div>';
  46. }
  47. }
  48. }
  49. if (!$error) {
  50. $mysql['ppc_network_id'] = mysql_real_escape_string($_POST['ppc_network_id']);
  51. $mysql['ppc_account_name'] = mysql_real_escape_string($_POST['ppc_account_name']);
  52. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  53. $mysql['ppc_account_time'] = time();
  54. if ($editing == true) { $ppc_account_sql = " UPDATE 202_ppc_accounts SET"; }
  55. else { $ppc_account_sql = " INSERT INTO 202_ppc_accounts SET"; }
  56. $ppc_account_sql .= " ppc_account_name='".$mysql['ppc_account_name']."',
  57. ppc_network_id='".$mysql['ppc_network_id']."',
  58. user_id='".$mysql['user_id']."',
  59. ppc_account_time='".$mysql['ppc_account_time']."'";
  60. if ($editing == true) { $ppc_account_sql .= "WHERE ppc_account_id='".$mysql['ppc_account_id']."'"; }
  61. $ppc_account_result = _mysql_query($ppc_account_sql) ; //($ppc_account_sql);
  62. $add_success = true;
  63. if ($editing == true) {
  64. //if editing true, refresh back with the edit get variable GONE GONE!
  65. header('location: /setup/ppc_accounts.php');
  66. }
  67. }
  68. }
  69. }
  70. if (isset($_GET['delete_ppc_network_id'])) {
  71. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  72. $mysql['ppc_network_id'] = mysql_real_escape_string($_GET['delete_ppc_network_id']);
  73. $mysql['ppc_network_time'] = time();
  74. $delete_sql = " UPDATE `202_ppc_networks`
  75. SET `ppc_network_deleted`='1',
  76. `ppc_network_time`='".$mysql['ppc_network_time']."'
  77. WHERE `user_id`='".$mysql['user_id']."'
  78. AND `ppc_network_id`='".$mysql['ppc_network_id']."'";
  79. if ($delete_result = _mysql_query($delete_sql)) { //($delete_result)) {
  80. $delete_success = true;
  81. }
  82. }
  83. if (isset($_GET['delete_ppc_account_id'])) {
  84. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  85. $mysql['ppc_account_id'] = mysql_real_escape_string($_GET['delete_ppc_account_id']);
  86. $mysql['ppc_account_time'] = time();
  87. $delete_sql = " UPDATE `202_ppc_accounts`
  88. SET `ppc_account_deleted`='1',
  89. `ppc_account_time`='".$mysql['ppc_account_time']."'
  90. WHERE `user_id`='".$mysql['user_id']."'
  91. AND `ppc_account_id`='".$mysql['ppc_account_id']."'";
  92. if ($delete_result = _mysql_query($delete_sql)) {
  93. $delete_success = true;
  94. }
  95. }
  96. if ($_GET['edit_ppc_account_id']) {
  97. $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  98. $mysql['ppc_account_id'] = mysql_real_escape_string($_GET['edit_ppc_account_id']);
  99. $ppc_account_sql = "SELECT *
  100. FROM `202_ppc_accounts`
  101. WHERE `ppc_account_id`='".$mysql['ppc_account_id']."'
  102. AND `user_id`='".$mysql['user_id']."'";
  103. $ppc_account_result = _mysql_query($ppc_account_sql) ; //($ppc_account_sql);
  104. $ppc_account_row = mysql_fetch_assoc($ppc_account_result);
  105. $selected['ppc_network_id'] = $ppc_account_row['ppc_network_id'];
  106. $html['ppc_account_name'] = htmlentities($ppc_account_row['ppc_account_name'], ENT_QUOTES, 'UTF-8');
  107. }
  108. if ($error) {
  109. //if someone happend take the post stuff and add it
  110. $selected['ppc_network_id'] = $_POST['ppc_network_id'];
  111. $html['ppc_account_name'] = htmlentities($_POST['ppc_account_name'], ENT_QUOTES, 'UTF-8');
  112. }
  113. template_top('Pay Per Click Accounts',NULL,NULL,NULL);
  114. ?>
  115. <div id="info">
  116. <h2>PPC Account Setup</h2>
  117. Just add the PPC networks you use, and usernames for each PPC account you have.
  118. </div>
  119. <table cellspacing="0" cellpadding="0" class="setup">
  120. <tr valign="top">
  121. <td>
  122. <? if ($error) { ?>
  123. <div class="warning"><div><h3>There were errors with your submission.</h3></div></div>
  124. <? } echo $error['token']; ?>
  125. <? if ($add_success == true) { ?>
  126. <div class="success"><div><h3>Your submission was successful</h3></div></div>
  127. <? } ?>
  128. <? if ($delete_success == true) { ?>
  129. <div class="success"><div><h3>You deletion was successful</h3>You have succesfully removed an account.</div></div>
  130. <? } ?>
  131. <form method="post" action="<? echo $_SERVER['REDIRECT_URL']; ?>">
  132. <table style="margin: 0px auto;">
  133. <tr>
  134. <td colspan="2" style="width: 400px;">
  135. <h3 class="green">1st - Add Pay-Per-Click Networks</h3>
  136. <p style="text-align: justify;">What ppc companies do you use? Example: Yahoo SearchMarketing, MSN Adcenter, Google Adwords, etc etc. First add what PPC networks you use, then follow by adding your accounts to the networks you use.</p>
  137. </td>
  138. </tr>
  139. <tr><td/><br/></tr>
  140. <tr>
  141. <td class="left_caption">PPC Network</td>
  142. <td>
  143. <input type="text" name="ppc_network_name" style="display: inline;" maxlength="50"/>
  144. <input type="submit" value="Add" style="display: inline; margin-left: 10px;"/>
  145. </td>
  146. </tr>
  147. </table>
  148. <? echo $error['ppc_network_name']; ?>
  149. </form>
  150. <form method="post" action="<? if ($delete_success == true) { echo $_SERVER['REDIRECT_URL']; }?>" style>
  151. <table style="margin-top: 35px;">
  152. <tr>
  153. <td colspan="2" style="width: 400px;">
  154. <h3 class="green">2nd - Add Individual Accounts</h3>
  155. <p style="text-align: justify;">Here you add each individual account you have for each PPC network you use. For instance, if you have two Yahoo Accounts, you can add them both here. This way we can track how each individual ppc account, on each network is doing.</p>
  156. </td>
  157. </tr>
  158. <tr><td/><br/></tr>
  159. <tr>
  160. <td class="left_caption">PPC Network</td>
  161. <td>
  162. <select name="ppc_network_id">
  163. <option value=""> -- </option>
  164. <? $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  165. $ppc_network_sql = "SELECT * FROM `202_ppc_networks` WHERE `user_id`='".$mysql['user_id']."' AND `ppc_network_deleted`='0' ORDER BY `ppc_network_name` ASC";
  166. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  167. while ($ppc_network_row = mysql_fetch_array($ppc_network_result, MYSQL_ASSOC)) {
  168. $html['ppc_network_name'] = htmlentities($ppc_network_row['ppc_network_name'], ENT_QUOTES, 'UTF-8');
  169. $html['ppc_network_id'] = htmlentities($ppc_network_row['ppc_network_id'], ENT_QUOTES, 'UTF-8');
  170. if ($selected['ppc_network_id'] == $ppc_network_row['ppc_network_id']) {
  171. printf('<option selected="selected" value="%s">%s</option>', $html['ppc_network_id'],$html['ppc_network_name']);
  172. } else {
  173. printf('<option value="%s">%s</option>', $html['ppc_network_id'],$html['ppc_network_name']);
  174. }
  175. } ?>
  176. </select>
  177. </td>
  178. </tr>
  179. <tr>
  180. <td class="left_caption">Account Username</td>
  181. <td>
  182. <input type="text" name="ppc_account_name" style="display: inline;" value="<? echo $html['ppc_account_name']; ?>"/>
  183. <input type="submit" value="<? if ($editing == true) { echo 'Edit'; } else { echo 'Add'; } ?>" style="display: inline; margin-left: 10px;"/>
  184. <? if ($editing == true) { ?>
  185. <input type="submit" value="Cancel" style="display: inline; margin-left: 10px;" onclick="window.location='/setup/ppc_accounts.php'; return false; "/>
  186. <? } ?>
  187. </td>
  188. </tr>
  189. </table>
  190. <? echo $error['ppc_network_id']; ?>
  191. <? echo $error['ppc_account_name']; ?>
  192. <? echo $error['wrong_user']; ?>
  193. </form>
  194. </td>
  195. <td class="setup-right" rowspan="2">
  196. <h3 class="green">My PPC Accounts</h3>
  197. <ul>
  198. <? $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  199. $ppc_network_sql = "SELECT * FROM `202_ppc_networks` WHERE `user_id`='".$mysql['user_id']."' AND `ppc_network_deleted`='0' ORDER BY `ppc_network_name` ASC";
  200. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  201. if (mysql_num_rows($ppc_network_result) == 0 ) {
  202. ?><li>You have not added any networks.</li><?
  203. }
  204. while ($ppc_network_row = mysql_fetch_array($ppc_network_result, MYSQL_ASSOC)) {
  205. //print out the PPC networks
  206. $html['ppc_network_name'] = htmlentities($ppc_network_row['ppc_network_name'], ENT_QUOTES, 'UTF-8');
  207. $url['ppc_network_id'] = urlencode($ppc_network_row['ppc_network_id']);
  208. printf('<li>%s - <a href="?delete_ppc_network_id=%s" style="font-size: 9px;">remove</a></li>', $html['ppc_network_name'],$url['ppc_network_id']);
  209. ?><ul style="margin-top: 0px;"><?
  210. //print out the individual accounts per each PPC network
  211. $mysql['ppc_network_id'] = mysql_real_escape_string($ppc_network_row['ppc_network_id']);
  212. $ppc_account_sql = "SELECT * FROM `202_ppc_accounts` WHERE `ppc_network_id`='".$mysql['ppc_network_id']."' AND `ppc_account_deleted`='0' ORDER BY `ppc_account_name` ASC";
  213. $ppc_account_result = _mysql_query($ppc_account_sql) ; //($ppc_account_sql);
  214. while ($ppc_account_row = mysql_fetch_array($ppc_account_result, MYSQL_ASSOC)) {
  215. $html['ppc_account_name'] = htmlentities($ppc_account_row['ppc_account_name'], ENT_QUOTES, 'UTF-8');
  216. $url['ppc_account_id'] = urlencode($ppc_account_row['ppc_account_id']);
  217. printf('<li>%s - <a href="?edit_ppc_account_id=%s" style="font-size: 9px;">edit</a> - <a href="?delete_ppc_account_id=%s" style="font-size: 9px;">remove</a></li>', $html['ppc_account_name'],$url['ppc_account_id'],$url['ppc_account_id']);
  218. }
  219. ?></ul><?
  220. } ?>
  221. </ul>
  222. </td>
  223. </tr>
  224. </table>
  225. <? template_bottom();