Guest User

Untitled

a guest
Jun 3rd, 2017
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. global $wpdb;
  3. $service_table_name = $wpdb->prefix . "ap_services";
  4. $all_services = $wpdb->get_results("SELECT `id`, `name` FROM `$service_table_name`");
  5. $staff_table_name = $wpdb->prefix . "ap_staff";
  6. $all_staffs = $wpdb->get_results("SELECT `id`, `name` FROM `$staff_table_name`");
  7. ?>
  8. <div class="bs-docs-example tooltip-demo">
  9. <div style="background:#C3D9FF; margin-bottom:10px; padding-left:10px;">
  10. <h3><i class="fa fa-edit"></i> <?php _e('Manage Appointments','appointzilla'); ?></h3>
  11. </div>
  12.  
  13. <form action="" method="post" name="manage-appointments">
  14. <table width="100%" border="0" class="table">
  15. <tr>
  16. <td colspan="8" scope="col">
  17. <div style="float:left;">
  18. <select name="filtername">
  19. <option value="All" <?php if(isset($_POST['filtername']) == 'All') echo "selected"; ?> <?php if(isset($_GET['filtername']) == 'All') echo "selected"; ?> ><?php _e('All Appointments','appointzilla'); ?></option>
  20.  
  21.  
  22. <option value="pending" <?php if(isset($_POST['filtername'])){ if($_POST['filtername'] == 'pending') echo "selected"; } ?> <?php if(isset($_GET['filtername'])){ if($_GET['filtername'] == 'pending') echo "selected"; } ?> > <?php _e('Pending Appointments','appointzilla'); ?></option>
  23. <option value="approved" <?php if(isset($_POST['filtername'])){ if($_POST['filtername'] == 'approved') echo "selected"; } ?> <?php if(isset($_GET['filtername'])){ if($_GET['filtername'] == 'approved') echo "selected"; } ?>> <?php _e('Approved Appointments','appointzilla'); ?> </option>
  24. <option value="cancelled" <?php if(isset($_POST['filtername'])){ if($_POST['filtername'] == 'cancelled') echo "selected"; } ?> <?php if(isset($_GET['filtername'])){ if($_GET['filtername'] == 'cancelled') echo "selected"; } ?> ><?php _e('Cancelled Appointments','appointzilla'); ?></option>
  25. <option value="done" <?php if(isset($_POST['filtername'])){ if($_POST['filtername'] == 'done') echo "selected"; } ?> <?php if(isset($_GET['filtername'])){ if($_GET['filtername'] == 'done') echo "selected"; } ?> ><?php _e('Completed Appointments','appointzilla'); ?></option>
  26. <option value="today" <?php if(isset($_POST['filtername'])){ if($_POST['filtername'] == 'today') echo "selected"; } ?> <?php if(isset($_GET['filtername'])){ if($_GET['filtername'] == 'today') echo "selected"; } ?> ><?php _e('Today`s Appointments','appointzilla'); ?></option>
  27.  
  28.  
  29. </select>
  30. </div>&nbsp;<button id="filter" class="btn btn-small btn-info" type="submit" name="filter" ><i class="icon-th-list icon-white"></i> <?php _e('Filter Appointments','appointzilla'); ?></button>
  31. &nbsp;<a href="#" rel="tooltip" title="<?php _e("Filter Appointments",'appointzilla')?>" ><i class="icon-question-sign"></i></a>
  32. </td>
  33. </tr>
  34. </table>
  35. </form>
  36.  
  37. <?php
  38. $NoOfRow = 10;
  39. $Offset = 0;
  40. $FilterData = 'All';
  41. $PageNo = 1;
  42. // pagination start with page no = 1 when filter
  43. if(!isset($_POST['filter'])) {
  44. if(!empty($_GET['pageno'])){
  45. $PageNo = $_GET['pageno'];
  46. $Offset = ($PageNo-1)*$NoOfRow;
  47. }
  48. }
  49.  
  50. if(isset($_POST['filter'])) {
  51. global $wpdb;
  52. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  53. $FilterData = $_POST['filtername'];
  54.  
  55.  
  56.  
  57. if($FilterData =='today') {
  58. $today_date = date('Y-m-d'); // first time pagination data and total page like 1 2 3 only today
  59. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `date` ='$today_date' ORDER BY `date` DESC limit $Offset, $NoOfRow ");
  60. $cat=$wpdb->get_results("select * from `$AppointmentTableName` WHERE `date` ='$today_date' ORDER BY `date` DESC");
  61. }
  62.  
  63. if($FilterData =='pending') {
  64. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='pending' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  65. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='pending' ORDER BY `date` DESC");
  66. }
  67.  
  68. if($FilterData =='approved') {
  69. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='approved' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  70. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='approved' ORDER BY `date` DESC");
  71. }
  72.  
  73. if($FilterData =='cancelled') {
  74. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='cancelled' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  75. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='cancelled' ORDER BY `date` DESC");
  76. }
  77.  
  78. if($FilterData =='All') {
  79. //first time pagination data and total page like 1 2 3 only All appointment filter
  80. $table_name = $wpdb->prefix . "ap_appointments";
  81. $all_appointments = $wpdb->get_results("select * from `$table_name` ORDER BY `date` DESC limit $Offset,$NoOfRow");
  82. $cat = $wpdb->get_results("select * from `$table_name` ORDER BY `date` DESC");
  83. }
  84. } else {
  85.  
  86. // filter pagination with get filter
  87. if(isset($_GET['filtername'])) {
  88. global $wpdb;
  89. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  90. $FilterData = $_GET['filtername'];
  91.  
  92. //if filter by service n staff
  93. $underscore_pos = stripos($FilterData, '-');
  94. $filter_by = substr($FilterData, 0, $underscore_pos);
  95.  
  96. if($filter_by == 'service') {
  97. $service_id = substr($FilterData, $underscore_pos + 1);
  98. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  99. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `service_id` = '$service_id' ORDER BY `date` DESC limit $Offset, $NoOfRow ");
  100. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `service_id` ='$service_id' ORDER BY `date` DESC");
  101. }
  102.  
  103. if($filter_by == 'staff') {
  104. $staff_id = substr($FilterData, $underscore_pos + 1);
  105. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  106. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `staff_id` = '$staff_id' ORDER BY `date` DESC limit $Offset, $NoOfRow ");
  107. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `staff_id` ='$staff_id' ORDER BY `date` DESC");
  108. }
  109.  
  110. if($FilterData =='today') {
  111. $today_date = date('Y-m-d');
  112. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `date` ='$today_date' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  113. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `date` ='$today_date' ORDER BY `date` DESC");
  114. }
  115.  
  116. if($FilterData =='pending') {
  117. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='pending' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  118. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='pending' ORDER BY `date` DESC");
  119. }
  120.  
  121. if($FilterData =='approved') {
  122. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='approved' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  123. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='approved' ORDER BY `date` DESC");
  124. }
  125.  
  126. if($FilterData =='cancelled') {
  127. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='cancelled' ORDER BY `date` DESC limit $Offset,$NoOfRow");
  128. $cat = $wpdb->get_results("select * from `$AppointmentTableName` WHERE `status` ='cancelled' ORDER BY `date` DESC");
  129. }
  130.  
  131.  
  132.  
  133. //pagination get value
  134. if($FilterData =='All') {
  135. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` ORDER BY `date` DESC limit $Offset,$NoOfRow");
  136. $cat = $wpdb->get_results("select * from `$AppointmentTableName` ORDER BY `date` DESC");
  137. }
  138. } else {
  139. //all appointment with pagination
  140. global $wpdb;
  141. $AppointmentTableName = $wpdb->prefix . "ap_appointments";
  142. $all_appointments = $wpdb->get_results("select * from `$AppointmentTableName` ORDER BY `date` DESC limit $Offset, $NoOfRow");
  143. $cat = $wpdb->get_results("select * from `$AppointmentTableName` ORDER BY `date` DESC");
  144. }
  145. }?>
  146.  
  147. <form action="" method="post" name="manage-appointments">
  148. <table width="100%" border="0" class="table table-hover">
  149. <tr>
  150. <th align="left" scope="col"><?php _e('No.','appointzilla'); ?></th>
  151. <th align="left" scope="col"><?php _e('Name','appointzilla'); ?></th>
  152.  
  153. <th align="left" scope="col"><?php _e('Date','appointzilla'); ?></th>
  154. <th align="left" scope="col"><?php _e('Time','appointzilla'); ?></th>
  155. <th align="left" scope="col"><?php _e('Service','appointzilla'); ?></th>
  156.  
  157. <th align="left" scope="col"><?php _e('Status','appointzilla'); ?></th>
  158.  
  159. <th align="left" scope="col"><?php _e('Action','appointzilla'); ?></th>
  160. <th style="text-align: center;" scope="col"><a href="#" rel="tooltip" data-placement="left" title="<?php _e('Select All','appointzilla'); ?>"><input type="checkbox" id="checkbox" name="checkbox[]" value="0" /></a></th>
  161. </tr>
  162. <?php
  163. //get all appointments list
  164. $i = 1;
  165. if($all_appointments) {
  166. foreach($all_appointments as $appointment) { ?>
  167. <tr>
  168. <td><em><?php echo $i."."; ?></em></td>
  169. <td><em><?php echo ucwords($appointment->name); ?></em></td>
  170.  
  171. <td>
  172. <em>
  173. <?php
  174. $DateFormat = get_option('apcal_date_format');
  175. if($appointment->recurring == 'yes')
  176. echo date($DateFormat, strtotime($appointment->recurring_st_date))." - ".date($DateFormat, strtotime($appointment->recurring_ed_date));
  177. else
  178. echo date($DateFormat, strtotime($appointment->date));
  179. ?>
  180. </em>
  181. </td>
  182. <td>
  183. <em>
  184. <?php
  185. if($TimeFormat == 'h:i') $ATimeFormat = "g:ia"; else $ATimeFormat = "G:i";
  186. echo date($ATimeFormat, strtotime($appointment->start_time))." - ".date($ATimeFormat, strtotime($appointment->end_time));
  187. ?>
  188. </em>
  189. </td>
  190. <td>
  191. <em>
  192. <?php
  193. $apppid=$appointment->service_id;
  194. $servicedetails= $wpdb->get_row("SELECT * FROM $service_table_name WHERE `id` = '$apppid'");
  195. echo ucfirst($servicedetails->name);
  196. ?>
  197. </em>
  198. </td>
  199.  
  200. <td>
  201. <em><?php echo _e(ucfirst($appointment->status), 'appointzilla'); ?></em>
  202. </td>
  203.  
  204. <td>
  205. <a href="?page=update-appointment&viewid=<?php echo $appointment->id; ?>" title="<?php _e('View','appointzilla'); ?>" rel="tooltip"><i class="icon-eye-open"></i></a>&nbsp;
  206. <a href="?page=update-appointment&updateid=<?php echo $appointment->id; ?>" title="<?php _e('Update','appointzilla'); ?>" rel="tooltip"><i class="icon-pencil"></i></a>&nbsp;
  207. <a href="?page=manage-appointments&delete=<?php echo $appointment->id; ?>" rel="tooltip" title="<?php _e('Delete','appointzilla'); ?>"
  208. onclick="return confirm('<?php _e('Do you want to delete this appointment?','appointzilla'); ?>')"><i class="icon-remove" ></i></a></td>
  209. <td style="text-align: center;"><a rel="tooltip" title="<?php _e('Select','appointzilla'); ?>"><input type="checkbox" id="checkbox" name="checkbox[]" value="<?php echo $appointment->id; ?>" /></a></td>
  210. </tr>
  211. <?php $i++; } ?>
  212. <tr>
  213. <td colspan="7">
  214. <ul id="pagination-flickr" style="border:1px #CCCCCC;">
  215. <li><a href="?page=manage-appointments&pageno=1&filtername=<?php echo $FilterData; ?>" ><?php _e('First','appointzilla'); ?> </a> </li>
  216. <?php // pagination list items
  217. if(isset($_GET['pageno'])) { $pgno = $_GET['pageno']; } else { $pgno = 1; }
  218. $catrow = count($cat);
  219. $page = ceil($catrow/$NoOfRow);
  220. for($i=1; $i<=$page; $i++){ ?>
  221. <li>
  222. <a href="?page=manage-appointments&pageno=<?php echo $i?>&filtername=<?php echo $FilterData; ?>" <?php if($pgno == $i ) echo "class='active'"; else echo "class=''"; ?> ><?php echo $i; ?> </a>
  223. </li>
  224. <?php } ?>
  225. <li>
  226. <a href="?page=manage-appointments&pageno=<?php echo $i-1 ?>&filtername=<?php echo $FilterData; ?>"><?php _e('Last','appointzilla'); ?></a>
  227. </li>
  228. </ul>
  229. </td>
  230. <td style="text-align: center;"><button name="deleteall" class="btn btn-danger" type="submit" id="deleteall" onclick="return confirm('<?php _e('Do you want to delete these appointments?','appointzilla'); ?>')" ><i class="icon-trash icon-white"></i> <?php _e("Delete", "appointzilla"); ?></button></td>
  231. </tr>
  232. <?php } else { ?>
  233. <tr class="alert"><td colspan="7"><strong><?php _e('Sorry No Appointment(s).','appointzilla'); ?></strong></td>
  234. <td>&nbsp;</td>
  235. </tr>
  236.  
  237. <?php } ?>
  238. </table>
  239. </form>
  240.  
  241. <script>
  242. function Changestatus(appid) {
  243. var Appstatus ="#Appstatus"+appid;
  244. var Appstatuslist ="#Appstatuslist"+appid;
  245. var retunappstatusdiv ="#retunappstatusdiv"+appid;
  246. jQuery(Appstatus).hide();
  247. jQuery(retunappstatusdiv).hide();
  248. jQuery(Appstatuslist).show();
  249. }
  250.  
  251. function appchangestatus(appid) {
  252. var Appstatuslist = "#Appstatuslist"+appid;
  253. var appchangestatus = "#appchangestatus"+appid;
  254. var retunappstatusdiv = "#retunappstatusdiv"+appid;
  255. var lodingimagediv = "#lodingimagediv"+appid;
  256. var status =jQuery(appchangestatus).val();
  257.  
  258. jQuery(Appstatuslist).hide();
  259. jQuery(retunappstatusdiv).show();
  260. jQuery(lodingimagediv).show();
  261.  
  262. var url ='?page=manage-appointments';
  263. var datastring = "appid="+appid+"&appstatus="+status;
  264. jQuery.ajax({
  265. type : "POST",
  266. cache : false,
  267. url : url,
  268. data : datastring,
  269. success : function(data) {
  270. jQuery(retunappstatusdiv).html("<a href='#'>" + status[0].toUpperCase()+ status.slice(1) + "</a>");
  271. jQuery(lodingimagediv).hide();
  272. var currenturl = jQuery(location).attr('href');
  273. }
  274. });
  275. }
  276. </script>
  277. <?php // update appointment status
  278. if(isset($_POST['appid']) && isset($_POST['appstatus'])) {
  279. global $wpdb;
  280. $AppointmentsTable = $wpdb->prefix."ap_appointments";
  281. $status = $_POST['appstatus'];
  282. $up_app_id = $_POST['appid'];
  283. $update_appointment ="UPDATE `$AppointmentsTable` SET `status` = '$status' WHERE `id` = '$up_app_id'";
  284. if($wpdb->query($update_appointment)) {
  285. $Appointment_details = $wpdb->get_row("SELECT * FROM `$AppointmentsTable` WHERE `id` = '$up_app_id' ", OBJECT);
  286. $name = strip_tags($Appointment_details->name);
  287. $email = $Appointment_details->email;
  288. $serviceid = $Appointment_details->service_id;
  289. $staffid = $Appointment_details->staff_id;
  290. $phone = $Appointment_details->phone;
  291. $start_time = date("h:i A", strtotime($Appointment_details->start_time));
  292. $end_time = date("h:i A", strtotime($Appointment_details->end_time));
  293. $appointmentdate = date("Y-m-d", strtotime($Appointment_details->date));
  294. $note = strip_tags($Appointment_details->note);
  295. $status = $Appointment_details->status;
  296. $recurring = $Appointment_details->recurring;
  297. $recurring_type = $Appointment_details->recurring_type;
  298. $recurring_st_date = date("Y-m-d", strtotime($Appointment_details->recurring_st_date));
  299. $recurring_ed_date = date("Y-m-d", strtotime($Appointment_details->recurring_ed_date));
  300. $appointment_by = $Appointment_details->appointment_by;
  301.  
  302.  
  303. //send notification to client if appointment approved or cancelled
  304. if($status == 'approved' || $status == 'cancelled' ) {
  305. $GetAppKey = $wpdb->get_row("SELECT * FROM `$AppointmentsTable` WHERE `id` = '$up_app_id' ", OBJECT);
  306.  
  307. $BlogName = get_bloginfo();
  308. $ClientTable = $wpdb->prefix . "ap_clients";
  309. $GetClient = $wpdb->get_row("SELECT * FROM `$ClientTable` WHERE `email` = '$email' ", OBJECT);
  310. if($up_app_id && $GetClient->id) {
  311. $AppId = $up_app_id;
  312. $ServiceId = $serviceid;
  313. $StaffId = $staffid;
  314. $ClientId = $GetClient->id;
  315. //include notification class
  316. require_once('notification-class.php');
  317. $Notification = new Notification();
  318. if($status == 'approved') $On = "approved";
  319. if($status == 'cancelled') {
  320. $On = "cancelled";
  321. //notify admin only on cancel any appointment
  322. $Notification->notifyadmin($On, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
  323. }
  324. //notify client
  325. $Notification->notifyclient($On, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
  326.  
  327. //notify staff
  328. if(get_option('staff_notification_status') == 'on') {
  329. $Notification->notifystaff($On, $AppId, $ServiceId, $StaffId, $ClientId, $BlogName, $DateFormat, $TimeFormat);
  330. }
  331. }
  332.  
  333. }// end send notification to client if appointment approved or cancelled ckech
  334.  
  335. $appointmentdate = date("Y-m-d",strtotime($appointmentdate));
  336. $recurring_st_date = date("Y-m-d",strtotime($recurring_st_date));
  337. $recurring_ed_date = date("Y-m-d",strtotime($recurring_ed_date));
  338.  
  339. //if status is approved then sync appointment
  340. if($status == 'approved') {
  341.  
  342. //add service name with event title($name)
  343. //$ServiceTable = $wpdb->prefix . "ap_services";
  344. //$ServiceData = $wpdb->get_row("SELECT * FROM `$ServiceTable` WHERE `id` = '$serviceid'");
  345. //$name = $name."(".$ServiceData->name.")";
  346.  
  347. /***
  348. * admin appointment sync
  349. */
  350. $CalData = get_option('google_caelndar_settings_details');
  351. if($CalData['google_calendar_client_id'] != '' && $CalData['google_calendar_secret_key'] != '') {
  352. $ClientId = $CalData['google_calendar_client_id'];
  353. $ClientSecretId = $CalData['google_calendar_secret_key'];
  354. $RedirectUri = $CalData['google_calendar_redirect_uri'];
  355. require_once('google-appointment-sync-class.php');
  356.  
  357. global $wpdb;
  358. $AppointmentSyncTable = $wpdb->prefix . "ap_appointment_sync";
  359. $AnySycnId = $wpdb->get_row("SELECT `id` FROM `$AppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  360. //check appointment already synced or first time approved
  361. if(count($AnySycnId)) {
  362. // update this appointment event on calendar
  363. global $wpdb;
  364. $AppointmentSyncTable = $wpdb->prefix . "ap_appointment_sync";
  365. $SyncDetails = $wpdb->get_row("SELECT * FROM `$AppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  366. $SyncTableRowId = $SyncDetails->id;
  367. $SyncDetailsData = unserialize($SyncDetails->app_sync_details);
  368. $json = json_encode($SyncDetailsData);
  369. $SyncDetailsData = json_decode($json, true);
  370. $sync_id = $SyncDetailsData['id'];
  371. $sync_email = $SyncDetailsData['creator']['email'];
  372.  
  373. $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
  374. $tag = "Appointment with: ";
  375. if($recurring_type == 'none') {
  376. $OAuth = $GoogleAppointmentSync->UpdateNormalSync($sync_id, $sync_email, $name, $appointmentdate, $start_time, $end_time, $note, $tag);
  377. }
  378. if($recurring_type != 'none') {
  379. $OAuth = $GoogleAppointmentSync->UpdateRecurringSync($sync_id, $sync_email, $name, $recurring_st_date, $recurring_ed_date, $start_time, $end_time, $recurring_type, $note, $tag);
  380. }
  381.  
  382. //update appointment sync details
  383. $OAuth = serialize($OAuth);
  384. $wpdb->query("UPDATE `$AppointmentSyncTable` SET `app_sync_details` = '$OAuth' WHERE `id` = '$SyncTableRowId'");
  385. } else {
  386. // insert this appointment event on calendar
  387. $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
  388. $tag = "Appointment with: ";
  389. if($recurring_type == 'none') {
  390. $OAuth = $GoogleAppointmentSync->NormalSync($name, $appointmentdate, $start_time, $end_time, $note, $tag);
  391. }
  392. if($recurring_type != 'none') {
  393. $OAuth = $GoogleAppointmentSync->RecurringSync($name, $recurring_st_date, $recurring_ed_date, $start_time, $end_time, $recurring_type, $note, $tag);
  394. }
  395.  
  396. //insert appointment sync details
  397. $OAuth = serialize($OAuth);
  398. $wpdb->query("INSERT INTO `$AppointmentSyncTable` ( `id` , `app_id` , `app_sync_details` ) VALUES ( NULL , '$up_app_id', '$OAuth' );");
  399. }
  400. }//end of if cal settings check
  401.  
  402.  
  403. /***
  404. * staff appointment sync
  405. */
  406. $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
  407. if($StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'] != "" && $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret']) {
  408. $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
  409. $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
  410. $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
  411. $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
  412. require_once('google-staff-appointment-sync-class.php');
  413.  
  414. //check staff appointment already synced or first time approved
  415. global $wpdb;
  416. $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
  417. $AnyStaffSycnId = $wpdb->get_row("SELECT `id` FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  418. if(count($AnyStaffSycnId)) {
  419. // update this staff appointment event on his google calendar
  420. global $wpdb;
  421. $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
  422. $SyncDetails = $wpdb->get_row("SELECT * FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  423. $SyncTableRowId = $SyncDetails->id;
  424. $SyncDetailsData = unserialize($SyncDetails->staff_sync_details);
  425. $json = json_encode($SyncDetailsData);
  426. $SyncDetailsData = json_decode($json, true);
  427. $sync_id = $SyncDetailsData['id'];
  428. $sync_email = $SyncDetailsData['creator']['email'];
  429.  
  430. $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
  431. $tag = __("Appointment with: ", "appointzilla");
  432. if($recurring_type == 'none') {
  433. $StaffOAuth = $StaffGoogleAppointmentSync->UpdateNormalStaffSync($staffid, $sync_id, $sync_email, $name, $appointmentdate, $start_time, $end_time, $note, $tag);
  434. }
  435. if($recurring_type != 'none') {
  436. $StaffOAuth = $StaffGoogleAppointmentSync->UpdateRecurringStaffSync($staffid ,$sync_id, $sync_email, $name, $recurring_st_date, $recurring_ed_date, $start_time, $end_time, $recurring_type, $note, $tag);
  437. }
  438.  
  439. } else {
  440. // add this staff appointment event on his google calendar
  441. $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
  442. $Tag = __("Appointment with: ", "appointzilla");
  443. if($recurring_type == 'none') {
  444. $StaffOAuth = $StaffGoogleAppointmentSync->NormalStaffAppointmentSync($staffid, $name, $appointmentdate, $start_time, $end_time, $note, $Tag);
  445. }
  446. if($recurring_type != 'none') {
  447. $StaffOAuth = $StaffGoogleAppointmentSync->RecurringStaffSync($staffid, $name, $recurring_st_date, $recurring_ed_date, $start_time, $end_time, $recurring_type, $note, $Tag);
  448. }
  449.  
  450. //insert staff appointment sync details
  451. $StaffOAuth = serialize($StaffOAuth);
  452. $wpdb->query("INSERT INTO `$StaffAppointmentSyncTable` ( `id` , `app_id` , `staff_sync_details` ) VALUES ( NULL , '$up_app_id', '$StaffOAuth' )");
  453. }
  454. }//end of staff appointment sync
  455. }//end of if approved*/
  456.  
  457.  
  458.  
  459.  
  460. /**
  461. * if status is cancelled then delete sync appointment
  462. */
  463. if($status == 'cancelled' || $status == 'pending') {
  464. global $wpdb;
  465. $AppointmentSyncTable = $wpdb->prefix . "ap_appointment_sync";
  466. $Row = $wpdb->get_row("SELECT * FROM `$AppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  467. if(count($Row)) {
  468. $Row = unserialize($Row->app_sync_details);
  469. $json = json_encode($Row);
  470. $Row = json_decode($json, true);
  471. $SyncId = $Row['id'];
  472. if($SyncId) {
  473. $CalData = get_option('google_caelndar_settings_details');
  474. $ClientId = $CalData['google_calendar_client_id'];
  475. $ClientSecretId = $CalData['google_calendar_secret_key'];
  476. $RedirectUri = $CalData['google_calendar_redirect_uri'];
  477.  
  478. require_once('google-appointment-sync-class.php');
  479. $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
  480. $OAuth = $GoogleAppointmentSync->DeleteSync($SyncId);
  481.  
  482. // delete sync details
  483. $wpdb->query("DELETE FROM `$AppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  484. }
  485. }
  486. }//end of cancel status check
  487.  
  488.  
  489.  
  490. /**
  491. * if status is cancelled then delete staff sync appointment
  492. */
  493. if($status == 'cancelled' || $status == 'pending') {
  494. global $wpdb;
  495. $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
  496. $StaffRow = $wpdb->get_row("SELECT * FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  497. if(count($StaffRow)) {
  498. $StaffRow = unserialize($StaffRow->staff_sync_details);
  499. $json = json_encode($StaffRow);
  500. $StaffRow = json_decode($json, true);
  501. $SyncId = $StaffRow['id'];
  502. if($SyncId) {
  503. $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
  504. $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
  505. $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
  506. $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
  507. $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
  508.  
  509. require_once('google-staff-appointment-sync-class.php');
  510. $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
  511. $StaffOAuth = $StaffGoogleAppointmentSync->DeleteStaffSync($staffid, $SyncId);
  512.  
  513. // delete sync details
  514. $wpdb->query("DELETE FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$up_app_id'");
  515. }
  516. }
  517. }//end of cancel status check
  518. } // end of update query
  519. }// end of isset appointment
  520. ?>
  521.  
  522.  
  523. <!--validation js lib-->
  524. <script src="<?php echo plugins_url('/js/jquery.min.js', __FILE__); ?>" type="text/javascript"></script>
  525. <script type="text/javascript">
  526. jQuery(document).ready(function() {
  527. jQuery('#checkbox').click(function(){
  528. if(jQuery('#checkbox').is(':checked')) {
  529. jQuery(":checkbox").prop("checked", true);
  530. } else {
  531. jQuery(":checkbox").prop("checked", false);
  532. }
  533. });
  534. });
  535. </script>
  536.  
  537. <?php
  538. /**
  539. * Deleting single appointment
  540. */
  541. if(isset($_GET['delete'])) {
  542. $AppointmentsTable = $wpdb->prefix . "ap_appointments";
  543. $DeleteId = $_GET['delete'];
  544. $StaffDetails = $wpdb->get_row("SELECT `staff_id` FROM `$AppointmentsTable` WHERE `id` = '$DeleteId'");
  545. $StaffId = $StaffDetails->staff_id;
  546. $DeleteAppointmentQuery = "DELETE FROM `$AppointmentsTable` WHERE `id` = '$DeleteId'";
  547. if($wpdb->query($DeleteAppointmentQuery)) {
  548.  
  549. /**
  550. * Delete admin sync appointment from his google calendar
  551. */
  552. global $wpdb;
  553. $AppointmentSyncTable = $wpdb->prefix . "ap_appointment_sync";
  554. $Row = $wpdb->get_row("SELECT * FROM `$AppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  555. if(count($Row)) {
  556. $Row = unserialize($Row->app_sync_details);
  557. $json = json_encode($Row);
  558. $Row = json_decode($json, true);
  559. $SyncId = $Row['id'];
  560. if($SyncId) {
  561. $CalData = get_option('google_caelndar_settings_details');
  562. $ClientId = $CalData['google_calendar_client_id'];
  563. $ClientSecretId = $CalData['google_calendar_secret_key'];
  564. $RedirectUri = $CalData['google_calendar_redirect_uri'];
  565.  
  566. require_once('google-appointment-sync-class.php');
  567. $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
  568. $OAuth = $GoogleAppointmentSync->DeleteSync($SyncId);
  569.  
  570. // delete sync details
  571. $wpdb->query("DELETE FROM `$AppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  572. }
  573. }
  574.  
  575. /**
  576. * Delete Staff sync appointment from his google calendar
  577. */
  578. $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
  579. $StaffRow = $wpdb->get_row("SELECT * FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  580. if(count($StaffRow)) {
  581. $StaffRow = unserialize($StaffRow->staff_sync_details);
  582. $json = json_encode($StaffRow);
  583. $StaffRow = json_decode($json, true);
  584. $SyncId = $StaffRow['id'];
  585. if($SyncId) {
  586. $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
  587. $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
  588. $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
  589. $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
  590. $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
  591.  
  592. require_once('google-staff-appointment-sync-class.php');
  593. $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
  594. $StaffOAuth = $StaffGoogleAppointmentSync->DeleteStaffSync($StaffId, $SyncId);
  595.  
  596. // delete sync details
  597. $wpdb->query("DELETE FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  598. }
  599. }
  600.  
  601. echo "<script>alert('".__('Appointment successfully deleted.','appointzilla')."');</script>";
  602. echo "<script>location.href='?page=manage-appointments';</script>";
  603. }
  604. }
  605.  
  606. // Delete multiple appointment with checkbox
  607. if(isset($_POST['deleteall'])) {
  608. global $wpdb;
  609. $AppointmentSyncTable = $wpdb->prefix . "ap_appointment_sync";
  610. $AppointmentsTable = $wpdb->prefix . "ap_appointments";
  611.  
  612. require_once('google-appointment-sync-class.php');
  613. require_once('google-staff-appointment-sync-class.php');
  614.  
  615. //admin sync details
  616. $CalData = get_option('google_caelndar_settings_details');
  617. $ClientId = $CalData['google_calendar_client_id'];
  618. $ClientSecretId = $CalData['google_calendar_secret_key'];
  619. $RedirectUri = $CalData['google_calendar_redirect_uri'];
  620. $GoogleAppointmentSync = new GoogleAppointmentSync($ClientId, $ClientSecretId, $RedirectUri);
  621.  
  622. // staff sync details
  623. $StaffAppointmentSyncTable = $wpdb->prefix . "ap_staff_appointment_sync";
  624. //for loop for each id access
  625. for($i=0; $i <= count($_POST['checkbox'])-1; $i++) {
  626. $res = $_POST['checkbox'][$i];
  627. $DeleteId = $res;
  628.  
  629. /**
  630. * Delete all selected admin sync appointment from his google calendar
  631. */
  632. $Row = $wpdb->get_row("SELECT * FROM `$AppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  633. if(count($Row)) {
  634. $Row = unserialize($Row->app_sync_details);
  635. $json = json_encode($Row);
  636. $Row = json_decode($json, true);
  637. $SyncId = $Row['id'];
  638. if($SyncId) {
  639. $OAuth = $GoogleAppointmentSync->DeleteSync($SyncId);
  640. // delete sync details
  641. $wpdb->query("DELETE FROM `$AppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  642. }
  643. }
  644.  
  645. /**
  646. * Delete Staff sync appointment from his google calendar
  647. */
  648. $StaffDetails = $wpdb->get_row("SELECT `staff_id` FROM `$AppointmentsTable` WHERE `id` = '$DeleteId'");
  649. if(count($StaffDetails)){
  650. $StaffId = $StaffDetails->staff_id;
  651. $StaffAppointmentSyncSettings = unserialize(get_option("staff_google_calendar_sync_settings_".$StaffId));
  652. $StaffGoogleEmail = $StaffAppointmentSyncSettings['StaffGoogleEmail'];
  653. $StaffGoogleCalendarClientId = $StaffAppointmentSyncSettings['StaffGoogleCalendarClientId'];
  654. $StaffGoogleCalendarSecret = $StaffAppointmentSyncSettings['StaffGoogleCalendarSecret'];
  655. $StaffGoogleCalendarRedirectUris = $StaffAppointmentSyncSettings['StaffGoogleCalendarRedirectUris'];
  656. $StaffGoogleAppointmentSync = new StaffGoogleAppointmentSync($StaffGoogleCalendarClientId, $StaffGoogleCalendarSecret, $StaffGoogleCalendarRedirectUris);
  657. $StaffRow = $wpdb->get_row("SELECT * FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  658. if(count($StaffRow)) {
  659. $StaffRow = unserialize($StaffRow->staff_sync_details);
  660. $json = json_encode($StaffRow);
  661. $StaffRow = json_decode($json, true);
  662. $SyncId = $StaffRow['id'];
  663. if($SyncId) {
  664. $StaffOAuth = $StaffGoogleAppointmentSync->DeleteStaffSync($StaffId, $SyncId);
  665. // delete sync details
  666. $wpdb->query("DELETE FROM `$StaffAppointmentSyncTable` WHERE `app_id` = '$DeleteId'");
  667. }
  668. }
  669. }
  670.  
  671. /**
  672. * Delete all selected appointment records
  673. */
  674. $DeleteAppointmentQuery = "DELETE FROM `$AppointmentsTable` WHERE `id` = '$DeleteId';";
  675. $wpdb->query($DeleteAppointmentQuery);
  676. }//end of for loop
  677.  
  678. if(count($_POST['checkbox'])) {
  679. echo "<script>alert('".__('Selected Appointment(s) successfully deleted.','appointzilla')."');</script>";
  680. echo "<script>location.href='?page=manage-appointments';</script>";
  681. } else {
  682. echo "<script>alert('".__('No Appointment(s) selected to delete.','appointzilla')."');</script>";
  683. echo "<script>location.href='?page=manage-appointments';</script>";
  684. }
  685. }?>
  686. </div>
  687.  
  688. <style type="text/css">
  689. .error{ color:#FF0000; }
  690. <style type="text/css">
  691. ul{border:0; margin:0; padding:0;}
  692.  
  693. #pagination-flickr li{
  694. border:0; margin:0; padding:0;
  695. font-size:11px;
  696. list-style:none;
  697. }
  698. #pagination-flickr a{
  699. border:solid 1px #C3D9FF;
  700. margin-right:5px;
  701. }
  702. #pagination-flickr .previous-off,
  703. #pagination-flickr .next-off {
  704. color:#666666;
  705. display:block;
  706. float:left;
  707. font-weight:bold;
  708. padding:3px 4px;
  709. }
  710. #pagination-flickr .next a,
  711. #pagination-flickr .previous a {
  712. font-weight:bold;
  713. border:solid 1px #FFFFFF;
  714. }
  715. #pagination-flickr .active{
  716. color:#ff0084;
  717. background:#C3D9FF;
  718. font-weight:bold;
  719. display:block;
  720. float:left;
  721. padding:4px 6px;
  722. }
  723. #pagination-flickr a:link,
  724. #pagination-flickr a:visited {
  725. color:#0063e3;
  726. display:block;
  727. float:left;
  728. padding:3px 6px;
  729. text-decoration:none;
  730. }
  731. #pagination-flickr a:hover{
  732. border:solid 1px #666666;
  733. }
  734. </style>
RAW Paste Data Copied