PageRenderTime 22ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/tracking202/setup/ppc_accounts.php

https://github.com/lsd/prosper202
PHP | 289 lines | 218 code | 65 blank | 6 comment | 56 complexity | b9c4ae0bdf93ab15d0ce576335b46344 MD5 | raw file
  1. <? include_once($_SERVER['DOCUMENT_ROOT'] . '/202-config/connect.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: /tracking202/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. <div id="info">
  115. <h2>PPC Account Setup</h2>
  116. Just add the PPC networks you use, and usernames for each PPC account you have.
  117. </div>
  118. <table cellspacing="0" cellpadding="0" class="setup">
  119. <tr valign="top">
  120. <td>
  121. <? if ($error) { ?>
  122. <div class="warning"><div><h3>There were errors with your submission.</h3></div></div>
  123. <? } echo $error['token']; ?>
  124. <? if ($add_success == true) { ?>
  125. <div class="success"><div><h3>Your submission was successful</h3></div></div>
  126. <? } ?>
  127. <? if ($delete_success == true) { ?>
  128. <div class="success"><div><h3>You deletion was successful</h3>You have succesfully removed an account.</div></div>
  129. <? } ?>
  130. <form method="post" action="<? echo $_SERVER['REDIRECT_URL']; ?>">
  131. <table style="margin: 0px auto;">
  132. <tr>
  133. <td colspan="2" style="width: 400px;">
  134. <h3 class="green">1st - Add Pay-Per-Click Networks</h3>
  135. <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>
  136. </td>
  137. </tr>
  138. <tr><td/><br/></tr>
  139. <tr>
  140. <td class="left_caption">PPC Network</td>
  141. <td>
  142. <input type="text" name="ppc_network_name" style="display: inline;" maxlength="50"/>
  143. <input type="submit" value="Add" style="display: inline; margin-left: 10px;"/>
  144. </td>
  145. </tr>
  146. </table>
  147. <? echo $error['ppc_network_name']; ?>
  148. </form>
  149. <form method="post" action="<? if ($delete_success == true) { echo $_SERVER['REDIRECT_URL']; }?>" style>
  150. <table style="margin-top: 35px;">
  151. <tr>
  152. <td colspan="2" style="width: 400px;">
  153. <h3 class="green">2nd - Add Individual Accounts</h3>
  154. <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>
  155. </td>
  156. </tr>
  157. <tr><td/><br/></tr>
  158. <tr>
  159. <td class="left_caption">PPC Network</td>
  160. <td>
  161. <select name="ppc_network_id">
  162. <option value=""> -- </option>
  163. <? $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  164. $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";
  165. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  166. while ($ppc_network_row = mysql_fetch_array($ppc_network_result, MYSQL_ASSOC)) {
  167. $html['ppc_network_name'] = htmlentities($ppc_network_row['ppc_network_name'], ENT_QUOTES, 'UTF-8');
  168. $html['ppc_network_id'] = htmlentities($ppc_network_row['ppc_network_id'], ENT_QUOTES, 'UTF-8');
  169. if ($selected['ppc_network_id'] == $ppc_network_row['ppc_network_id']) {
  170. printf('<option selected="selected" value="%s">%s</option>', $html['ppc_network_id'],$html['ppc_network_name']);
  171. } else {
  172. printf('<option value="%s">%s</option>', $html['ppc_network_id'],$html['ppc_network_name']);
  173. }
  174. } ?>
  175. </select>
  176. </td>
  177. </tr>
  178. <tr>
  179. <td class="left_caption">Account Username</td>
  180. <td>
  181. <input type="text" name="ppc_account_name" style="display: inline;" value="<? echo $html['ppc_account_name']; ?>"/>
  182. <input type="submit" value="<? if ($editing == true) { echo 'Edit'; } else { echo 'Add'; } ?>" style="display: inline; margin-left: 10px;"/>
  183. <? if ($editing == true) { ?>
  184. <input type="submit" value="Cancel" style="display: inline; margin-left: 10px;" onclick="window.location='/tracking202/setup/ppc_accounts.php'; return false; "/>
  185. <? } ?>
  186. </td>
  187. </tr>
  188. </table>
  189. <? echo $error['ppc_network_id']; ?>
  190. <? echo $error['ppc_account_name']; ?>
  191. <? echo $error['wrong_user']; ?>
  192. </form>
  193. </td>
  194. <td class="setup-right" rowspan="2">
  195. <h3 class="green">My PPC Accounts</h3>
  196. <ul>
  197. <? $mysql['user_id'] = mysql_real_escape_string($_SESSION['user_id']);
  198. $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";
  199. $ppc_network_result = _mysql_query($ppc_network_sql) ; //($ppc_network_sql);
  200. if (mysql_num_rows($ppc_network_result) == 0 ) {
  201. ?><li>You have not added any networks.</li><?
  202. }
  203. while ($ppc_network_row = mysql_fetch_array($ppc_network_result, MYSQL_ASSOC)) {
  204. //print out the PPC networks
  205. $html['ppc_network_name'] = htmlentities($ppc_network_row['ppc_network_name'], ENT_QUOTES, 'UTF-8');
  206. $url['ppc_network_id'] = urlencode($ppc_network_row['ppc_network_id']);
  207. 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']);
  208. ?><ul style="margin-top: 0px;"><?
  209. //print out the individual accounts per each PPC network
  210. $mysql['ppc_network_id'] = mysql_real_escape_string($ppc_network_row['ppc_network_id']);
  211. $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";
  212. $ppc_account_result = _mysql_query($ppc_account_sql) ; //($ppc_account_sql);
  213. while ($ppc_account_row = mysql_fetch_array($ppc_account_result, MYSQL_ASSOC)) {
  214. $html['ppc_account_name'] = htmlentities($ppc_account_row['ppc_account_name'], ENT_QUOTES, 'UTF-8');
  215. $url['ppc_account_id'] = urlencode($ppc_account_row['ppc_account_id']);
  216. 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']);
  217. }
  218. ?></ul><?
  219. } ?>
  220. </ul>
  221. </td>
  222. </tr>
  223. </table>
  224. <? template_bottom();