sr->category->activities->get(array('category'=>$category_id)); $interviews = $interviews_obj->get_activities(); //clean for ajax consumption $r = array(); foreach ($interviews as $key => $interview){ $r[] = array( 'id' => $interview['id'], 'label' => $interview['label'] ); } print json_encode($r); exit; } function sm_ajax_activity_search(){ $keyword = $_REQUEST['keyword']; new sm_wp_log("User searched for \"$keyword\""); $api = sm_api_factory(); $search_obj = $api->sr->activity->search->get(array('keyword'=>$keyword)); $search_list = $search_obj->get_results(); //clean for ajax consumption $r = array(); foreach ($search_list as $key => $search){ $r[] = array( 'id' => $search['id'], 'label' => $search['label'] ); } print json_encode($r); exit; } function sm_ajax_interview(){ $activity_id = intval($_REQUEST['activity_id']); $api = sm_api_factory(); $interview_obj = $api->sr->activity->interview->get(array("activity"=>$activity_id)); $questions = $interview_obj->get_questions(); print json_encode($questions); exit; } function sm_ajax_submit(){ $required = array("embeddable_id"); $type = "sp"; if ($_REQUEST['action'] == "sm_ajax_sr_submit") { $required[] = "activity_id"; $type = "sr"; } foreach ($required as $fld){ if (!isset($_REQUEST[$fld])){ throw new Exception("attribute '$fld' is required in admin_ajax form submission"); } } new sm_wp_log("Submitting form embeddable_id \"{$_REQUEST['embeddable_id']}\" via ajax"); $interview_params = array("id"=>$_REQUEST['embeddable_id'], "type"=>$type); if (!empty($_COOKIE['KWID_COOKIE'])){ $interview_params['kwid_override'] = $_COOKIE['KWID_COOKIE']; } $interview = sm_make_interview_from_embeddable($interview_params); $return_data = array(); if (!empty($_REQUEST) AND $interview->submit($_REQUEST)){ $interview->set_parameter("view", "thanks"); $interview->set_parameter("ajax", true); $return_data['message'] = $interview->render(); $return_data['track_id'] = $interview->get_submission_result()->get_track_id(); } else { $return_data['errors'] = $interview->get_validator()->get_errors(); } print json_encode($return_data); exit(); } function sm_ajax_history_data(){ global $wpdb; $sTable = $wpdb->prefix . "sm_log"; $sIndexColumn = "id"; $aColumns = array( 'timest', 'type', 'path', 'message', 'user_name' ); if (isset($_GET['iSortingCols']) AND $_GET['iSortingCols'] == 0){ $_GET['iSortingCols'] = "1"; $_GET['iSortCol_0'] = 0; $_GET['sSortDir_0'] = "desc"; } $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ". mysql_real_escape_string( $_GET['iDisplayLength'] ); } /* * Ordering */ $sOrder = ""; if ( isset( $_GET['iSortCol_0'] ) ) { $sOrder = "ORDER BY "; for ( $i=0 ; $iget_results( $sQuery ); $orig_tzs = date_default_timezone_get(); $tzs = get_option('timezone_string', ''); if (empty($tzs)){ if ($orig_tzs == 'UTC' OR empty($orig_tzs)){ $tzs = "Europe/Paris"; } else { $tzs = $orig_tzs; } } date_default_timezone_set($tzs); foreach($rResult as $key=>$res){ $rResult[$key]->timest = date('Y-m-d g:i A', $res->timest); } date_default_timezone_set($orig_tzs); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; $iFilteredTotal = $wpdb->get_col($sQuery); /* Total data set length */ $sQuery = " SELECT COUNT(`".$sIndexColumn."`) FROM $sTable "; $iTotal = $wpdb->get_col($sQuery); /* * Output */ $output = array( "sEcho" => intval(isset($_GET['sEcho']) ? $_GET['sEcho'] : 0), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); foreach ( $rResult as $aRow ) { $row = array(); for ( $i=0 ; $i$aColumns[$i]; } } $output['aaData'][] = $row; } echo json_encode( $output ); exit; } function sm_ajax_api_clear_cache(){ print sm_clear_api_cache(); exit(); }