Array returning empty - Facebook API - php

When i'm trying to receive all the data from a specific facebook page (that i have access, and garantee the access from my app) it return empty array.
But i use the same access_token in th graphic API explorer, i can see everything.
Any ideas why?!
Here's my code:
<?php
include (APPPATH.'libraries/facebook/facebook.php');
class Fbpages_users extends Facebook {
public function Fbpages_users($pages) {
$ci =& get_instance();
$ci->config->load('facebook', TRUE);
$config = $ci->config->item('facebook');
$facebook = new Facebook(array(
'appId' => '***********',
'secret' => '**********',
));
parent::__construct($config);
for ($x=0; $x<count($pages); $x++) {
try {
$pageFeed = $this->api('/'.$pages[$x]['page_id'].'/feed?access_token='.$pages[$x]['access_token']);
$this->pagefeed = $pageFeed;
echo "<pre>";print_r($pageFeed); echo "</pre>";
for ($i=0;$i<count($pageFeed['data']);$i++) {
for ($z=0;$z<count($pageFeed['data'][$i]['likes']['data']);$z++) {
$query_fb_user_likes = $ci->db->query("
SELECT user_id,id_fb_pages,type FROM fb_users
where user_id like " . $pageFeed['data'][$i]['likes']['data'][$z]['id']
. " AND id_fb_pages like " . $pages[$x]['id_fb_pages']
. " AND type like 1
");
$verifica_query_likes = $query_fb_user_likes->result_array();
if ( (empty($verifica_query_likes)) AND ($pages[$x]['page_id'] != $pageFeed['data'][$i]['likes']['data'][$z]['id']) )
{
$likes = array(
'id_fb_pages' => $pages[$x]['id_fb_pages'],
'user_id' => $pageFeed['data'][$i]['likes']['data'][$z]['id'],
'type' => '1'
);
$ci->db->insert('fb_users', $likes);
}
}
for ($s=0;$s<count($pageFeed['data'][$i]['comments']['data']);$s++) {
$query_fb_user_comments = $ci->db->query("
SELECT user_id,id_fb_pages,type FROM fb_users
where user_id like " . $pageFeed['data'][$i]['comments']['data'][$s]['from']['id']
. " AND id_fb_pages like " . $pages[$x]['id_fb_pages']
. " AND type like 2
");
$verifica_query_comments = $query_fb_user_comments->result_array();
if ( (empty($verifica_query_comments)) AND ($pages[$x]['page_id'] != $pageFeed['data'][$i]['comments']['data'][$s]['from']['id']) )
{
$comments = array(
'id_fb_pages' => $pages[$x]['id_fb_pages'],
'user_id' => $pageFeed['data'][$i]['comments']['data'][$s]['from']['id'],
'type' => '2'
);
$ci->db->insert('fb_users', $comments);
}
}
}
$checked_pages_getusers = array(
'page_id' => $pages[$x]['page_id'],
'date_checked' => date ("Y-m-d H:i:s")
);
$ci->db->insert('checked_pages_getusers', $checked_pages_getusers);
} catch (FacebookApiException $e) {
error_log($e);
$error = array(
'logtype' => $pages[$x]['page_id'] . " - pages-users",
'date' => date ("Y-m-d H:i:s"),
'error' => "'" . $e . "'"
);
$ci->db->insert('error_log', $error);
}
}
//redirect('main/login');
}
}
?>

Related

Change the Value field to percentage field in codeigniter OSPOS

This is add new gift page in OSPOS in CodeIGniter . there are four fields in that gifcard_id, person_id, giftcard_number, value I want Change the Value Field to Percentage of total price of the items that customer bought . the items are stored in another table. How can i do that ?
my model
/*
Gets gift card value
*/
public function get_giftcard_value($giftcard_number)
{
if( !$this->exists($this->get_giftcard_id($giftcard_number)) )
{
return 0;
}
$this->db->from('giftcards');
$this->db->where('giftcard_number', $giftcard_number);
return $this->db->get()->row()->value;
}
/*
Updates gift card value
*/
public function update_giftcard_value($giftcard_number, $value)
{
$this->db->where('giftcard_number', $giftcard_number);
$this->db->update('giftcards', array('value' => $value));
}
My Controller
public function save($giftcard_id = -1)
{
$giftcard_number = $this->input->post('giftcard_number');
if($giftcard_id == -1 && trim($giftcard_number) == '')
{
$giftcard_number = $this->Giftcard->generate_unique_giftcard_name($this->input->post('value'));
}
$giftcard_data = array(
'record_time' => date('Y-m-d H:i:s'),
'giftcard_number' => $giftcard_number,
'value' => parse_decimals($this->input->post('value')),
'person_id' => $this->input->post('person_id') == '' ? NULL : $this->input->post('person_id')
);
if($this->Giftcard->save($giftcard_data, $giftcard_id))
{
$giftcard_data = $this->xss_clean($giftcard_data);
//New giftcard
if($giftcard_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_adding') . ' ' .
$giftcard_data['giftcard_number'], 'id' => $giftcard_data['giftcard_id']));
}
else //Existing giftcard
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_updating') . ' ' .
$giftcard_data['giftcard_number'], 'id' => $giftcard_id));
}
}
else //failure
{
$giftcard_data = $this->xss_clean($giftcard_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('giftcards_error_adding_updating') . ' ' .
$giftcard_data['giftcard_number'], 'id' => -1));
}
}

Codeigniter Uploading excel and Saving to database (Network Error (tcp_error))

Really need your support on this one.
This works on intranet not until we decided to upload it on public.
Im using Codeigniter + SQL Server + Apache
This how it should work:
upload the excel file, read the content, save to database and send an email & sms.
But:
Everytime I upload the excel file after 3 Mins it stops and got this error written on Developer Opt->Network Tab:
"Network Error (tcp_error)
A communication error occurred: ""
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time."
Here's my code:
public function do_upload()
{
set_time_limit(0);
ignore_user_abort(1);
$accID = $this->input->get('acc');
$rmi = $this->input->get('rmi');
$spInst = $this->input->get('spInst');
$dateReq = '';
$dateReqq = $this->input->get('dateReq');
if($dateReqq==null or $dateReqq==''){
$dateReq = date('Y-m-d');
}else{
$dateReq = $this->input->get('dateReq');
}
$dateNow = date("F_d_Y__h_i_s__A");
$status = "";
$msg = "";
$file_element_name = 'file';
$file_name = '';
if ($status != "error")
{
$config['upload_path'] = 'c:/xampp/htdocs/eDR/assets/uploads/';
$config['allowed_types'] = 'xlsx';
$config['max_size'] = 60000;
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['file_name'] = uniqid('file')."_". $dateNow;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name))
{
$status = FALSE;
$msg = $this->upload->display_errors('', '');
}
else
{
$data = $this->upload->data();
//$file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']);
//if($file_id)
//{
$file_name = $data['file_name'];
$file = "c:/xampp/htdocs/eDR/assets/uploads/" . $file_name;
$this->do_read($file,$accID,$rmi,$spInst,$dateReq);
$status = TRUE;
$msg = "File successfully uploaded";
//}
//else
// {
// unlink($data['full_path']);
// $status = "error";
// $msg = "Something went wrong when saving the file, please try again.";
// }
}
#unlink($_FILES[$file_element_name]);
}
echo json_encode(array('status' => $status, 'msg' => $msg, 'name' => $file_name));
}
public function do_read($file,$accID,$rmi,$spInst,$dateReq){
//load the excel library
$this->load->library('excel');
//read file from path
$objPHPExcel = PHPExcel_IOFactory::load($file);
//get only the Cell Collection
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
//extract to a PHP readable array format
foreach ($cell_collection as $cell) {
$column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
//header will/should be in row 1 only. of course this can be modified to suit your need.
//if ($row == 1) {
// $header[$row][$column] = $data_value;
//} else {
$arr_data[$row][$column] = $data_value;
//}
}
//send the data in an array format
//$data['header'] = $header;
$drCount = ($this->up->get_DRcount($accID));
$date = date("F d, Y h:i: s A");
$data['values'] = $arr_data;
$last = count($arr_data) - 1;
$totalQty = 0;
$abbr = $this->up->get_Abbr($accID);
$TATnAGING = '';
$dAdd ='';
$posReq='';
$reqD;
foreach ($arr_data as $i => $row)
{
if( empty($row['B']) or
empty($row['C']) or
empty($row['D']) or
empty($row['E']) or
empty($row['F']) or
empty($row['G']) or
empty($row['H']) or
empty($row['I']) or
empty($row['J']) or
empty($row['K'])
){
$msg = 'B = ' . $row['B'] . ' C = ' . $row['C'] . ' D = ' . $row['D'] . ' E = ' . $row['E'] . ' F = ' . $row['F'] . ' G = ' . $row['G'] . ' H = ' . $row['H'] . ' I = ' . $row['I']
. ' J = ' . $row['J'] . ' K = ' . $row['K'] ;
$status = FALSE;
echo json_encode(array('status' => $status, 'msg'=>$msg));
exit();
}
}
foreach ($arr_data as $i => $row)
{
try {
$reqDatee = date('F d, Y', strtotime($dateReq));
$start = new DateTime( $reqDatee );
$end = new DateTime(date("F d, Y"));
$oneday = new DateInterval("P1D");
$days = array();
$data1 = "7.5";
foreach(new DatePeriod($start, $oneday, $end->add($oneday)) as $day) {
$day_num = $day->format("N"); /* 'N' number days 1 (mon) to 7 (sun) */
if($day_num < 6) { /* weekday */
$days[$day->format("Y-m-d")] = $data1;
}
}
$TATnAGING = count($days). ' day/s';
$dAdd = trim(strtoupper($row['D']));
$posReq = trim(strtoupper($row['B']));
$reqD = $dateReq;
$isFirst = ($i == 0);
$isLast = ($i == $last);
$id = $this->session->userdata('username');
$totalQty += $row['G'];
} catch (Exception $e) {
$msg = 'Caught exception: '. $e->getMessage(). "\n";
$status = FALSE;
echo json_encode(array('status' => $status, 'error'=>$msg));
exit();
}
if($i>1){
$data1 = array();
try {
if(trim(strtoupper($row['B']))=='YES' or trim(strtoupper($row['B']))=='Y'){
$data1 = array(
"drRef" => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
"postReq" => trim(strtoupper($row['B'])),
"reqDate" => $dateReq,
"reqBy" => trim(strtoupper($row['C'])),
"deliveryAcc" => trim(strtoupper($row['D'])),
"matCode" => trim(strtoupper($row['E'])),
"matDescription" => trim(strtoupper($row['F'])),
"qty" => $row['G'],
"UOM" => trim(strtoupper($row['H'])),
"location" => trim(strtoupper($row['I'])),
"postRef" => '',
// "postDate" => date("F d, Y h:i:s A"),
// "postBy" => $this->session->userdata['name'],
"status" => 'PENDING FOR POSTING',
// "TAT" => trim(strtoupper($row['O'])),
// "AGING" => trim(strtoupper($row['P'])),
"userID" => $id,
'addedBy' => $this->session->userdata('name'),
'addedUsing' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
'dateAdded' => $date,
'seqNo' => uniqid(),
'accID' => $accID,
'fromIMEI' => trim(strtoupper($row['J'])),
'toIMEI' => trim(strtoupper($row['K'])),
);
}else{
$data1 = array(
"drRef" => $abbr .'2017' . sprintf("%07d", ($drCount + 1)),
"postReq" => trim(strtoupper($row['B'])),
"reqDate" => $dateReq,
"reqBy" => trim(strtoupper($row['C'])),
"deliveryAcc" => trim(strtoupper($row['D'])),
"matCode" => trim(strtoupper($row['E'])),
"matDescription" => trim(strtoupper($row['F'])),
"qty" => $row['G'],
"UOM" => trim(strtoupper($row['H'])),
"location" => trim(strtoupper($row['I'])),
"postRef" => '',
"postDate" => date("F d, Y h:i:s A"),
"postBy" => $this->session->userdata['name'],
"status" => 'POSTED',
"TAT" => $TATnAGING,
"userID" => $id,
'addedBy' => $this->session->userdata('name'),
'addedUsing' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
'dateAdded' => $date,
'seqNo' => uniqid(),
'accID' => $accID,
'fromIMEI' => trim(strtoupper($row['J'])),
'toIMEI' => trim(strtoupper($row['K'])),
);
}
} catch (Exception $e) {
$msg = 'Caught exception: '. $e->getMessage(). "\n";
$status = FALSE;
echo json_encode(array('status' => $status, 'error'=>$msg));
exit;
}
$insert = $this->up->save($data1);
$data1 = array();
}
}
if($posReq=='YES' or $posReq=='Y'){
$data1 = array(
'drRef' => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
'accID' => $accID,
'userID' => $this->session->userdata['id'],
// 'postRef' => trim(strtoupper($row['K'])),
// 'postBy' => $this->session->userdata['name'],
// 'postDate' => $date,
'totQty' => $totalQty,
'status' => 'PENDING FOR POSTING',
'isPosted' => 'No',
'isApproved' => 'Pending',
'approverID' => $this->session->userdata('head'),
'postReq' => $posReq,
'reqDate' => $reqD,
'deliveryAdd' => $dAdd,
'reason' => urldecode($rmi),
'spInst' => urldecode($spInst),
);
}else{
$data1 = array(
'drRef' => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
'accID' => $accID,
'userID' => $this->session->userdata['id'],
//'postRef' => $this->session->userdata('username'),
'postBy' => $this->session->userdata['name'],
'postDate' => $date,
'totQty' => $totalQty,
'status' => 'POSTED',
'isPosted' => 'Yes',
'isApproved' => 'Pending',
'approverID' => $this->session->userdata('head'),
'postReq' => $posReq,
'tat' => $TATnAGING ,
'reqDate' => $reqD,
'deliveryAdd' => $dAdd,
'reason' => urldecode($rmi),
'spInst' => urldecode($spInst),
);
}
$insert = $this->up->saveOrder($data1);
$drRef = $abbr . '2017' . sprintf("%07d", ($drCount + 1));
$id = $this->up->get_Data('head','tblUser','userID',$this->session->userdata('id'));
$recepient = $this->up->get_Data('email','tblUser','userID',$id);
$name = $this->up->get_Data('name','tblUser','userID',$id);
$config = Array(
'protocol' => 'smtp',
'smtp_host' => '182.50.151.61',
'smtp_port' => 587,
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('eDR#domain.com', 'e - Delivery Receipt');
$this->email->to($recepient);
//$this->email->subject('eDR Notifications');
$this->email->subject('eDR Notification < DR Request >');
$message = 'Message';
$this->email->message($message);
$result = $this->email->send();
// if (!$result) {
// $this->email->print_debugger();
// }
$receiver = $this->up->get_Data('phoneNum','tblUser','userID',$this->session->userdata('head'));
$sms = array(
'receiver' => $receiver,
'msg' => 'message',
'status' => 'Send',
);
$this->up->sendSMS($sms);
}
Thanks.
I solved this problem via CRON job or calling cmd command on my PHP script so that it will execute the query on server itself really fast. :)

IPB php function works but is slow. SQL needs to be faster

I'm only using a small part of this function actually but I wanted to post it all to provide the big picture. There is a part of the query in this function that finds recent attachments a user has posted to the forums. The block is on the user profile. IT works but the problem is ... it's VERY slow!! Core attachments locks up for 30+ seconds and makes my site unusable.
Any one who could help it would be much appreciated.
private function getAttImages($limit, $forumIds = 0, $fidsReverse = false, $topicIds = 0, $membersIds = 0, $order = 'attach_date', $sort = 'desc', $group = null)
{
$fids = '';
if ($forumIds)
{
$r = '';
if ($fidsReverse)
{
$r = ' NOT ';
}
if (is_array($forumIds))
{
$forumIds = implode(',', $forumIds);
}
$fids = ' AND forums_topics.forum_id ' . $r . ' IN (' . $forumIds . ')';
}
$tids = '';
if ($topicIds)
{
$tids = ' AND forums_topics.tid IN (' . $topicIds . ')';
}
$mids = '';
if ($membersIds)
{
$mids = ' AND core_attachments.attach_member_id IN (' . $membersIds . ')';
}
$whereT = array();
$joinsT = array();
$findInPosts = ' AND ' . \IPS\Db::i()->findInSet('queued', array('0'));
$joinsT[] = array(
'select' => 'forums_posts.*',
'from' => 'forums_posts',
'where' => array("forums_posts.pid=core_attachments_map.id2" . $findInPosts),
);
$findInTopics = ' AND ' . \IPS\Db::i()->findInSet('approved', array('1'));
$joinsT[] = array(
'select' => 'forums_topics.*',
'from' => 'forums_topics',
'where' => array("forums_topics.tid=forums_posts.topic_id" . $findInTopics . $fids . $tids),
);
$select = 'core_attachments.attach_id AS custom_data, core_attachments.*';
if ($group)
{
$select = 'core_attachments.attach_id AS custom_data, COUNT(attach_is_image) as cnt_images, SUM(attach_hits) as summ_attach_hits, core_attachments.*';
}
$joinsT[] = array(
'select' => $select,
'from' => 'core_attachments',
'where' => array('core_attachments.attach_is_image=1 AND core_attachments.attach_is_archived=0 AND core_attachments.attach_id=core_attachments_map.attachment_id' . $mids),
);
$joinsT[] = array( 'select' => 'core_members.member_id, core_members.member_group_id, core_members.mgroup_others, core_members.name, core_members.members_seo_name',
'from' => 'core_members',
'where' => array('core_attachments.attach_member_id=core_members.member_id' . $mids),
);
$joinsT[] = array( 'select' => 'core_permission_index.perm_id',
'from' => 'core_permission_index',
'where' => array("core_permission_index.app='forums' AND core_permission_index.perm_type='forum' AND core_permission_index.perm_type_id=forums_topics.forum_id"),
);
$groupT = $group;
$whereT[] = array(
"core_attachments_map.location_key='forums_Forums' AND " .
\IPS\Db::i()->findInSet('perm_view', array_merge(array(\IPS\Member::loggedIn()->member_group_id), array_filter(explode(',', \IPS\Member::loggedIn()->mgroup_others)))) . " OR perm_view='*'" .
$fids . $tids . $mids
);
$table = new \IPS\Helpers\Table\Db(
'core_attachments_map',
\IPS\Http\Url::internal('app=core&module=system&controller=nbattachpictures', 'front', 'nbattachpictures'),
$whereT,
$groupT
);
$table->joins = $joinsT;
$table->limit = $limit;
$table->sortBy = $order;
$table->sortDirection = $sort;
$table->rowsTemplate = array(\IPS\Theme::i()->getTemplate('plugins', 'core', 'global'), 'nbAttachmentsBlocksRows');
$table->parsers = array(
'custom_data' => function( $val, $row )
{
return array(
'topic_data' => \IPS\Http\Url::internal("app=forums&module=forums&controller=topic&id={$row['tid']}", 'front', 'forums_topic', array($row['title_seo'])),
'summ_attach_hits' => $row['summ_attach_hits'],
'jewel' => $this->attachJewel($row['summ_attach_hits']),
);
},
);
return $table;
}

PHP: Array with foreach loop?

I have a and Array which looks like this:
$sms = array(
'from' => 'DummyFrom',
'to' => '+46709751949',
'message' => 'Hello hello!'
);
echo sendSMS ($sms) . "\n";
what i'm trying to do is to put this array within a foreach loop so it can be executed multiple time (based on the given times from mysql database). to explain it better, I did something like this:
if (is_array($g_numbers)) {
foreach ($g_numbers as $number) {
$sms = array(
'from' => 'DummyFrom',
'to' => "" . $number . "",
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}
but that is wrong and its stops the PHP page to execute properly without any errors!
Could someone please advise on this issue?
My full code :
<?php
$people = array();
$sql = "SELECT id, g_name, numbers FROM groups WHERE g_name='$groups'";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query);
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$g_id = $row['id'];
$g_name = $row['g_name'];
$g_numbers = $row['numbers'];
$people[$g_numbers] = $g_numbers;
}
?>
<?
// Example to send SMS using the 46elks service
// Change $username, $password and the mobile number to send to
function sendSMS($sms)
{
// Set your 46elks API username and API password here
// You can find them at https://dashboard.46elks.com/
$username = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$password = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Authorization: Basic " . base64_encode($username . ':' . $password) . "\r\n" . "Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query($sms),
'timeout' => 10
)
));
$response = file_get_contents('https://api.46elks.com/a1/SMS', false, $context);
if (!strstr($http_response_header[0], "200 OK"))
return $http_response_header[0];
return $response;
}
if (is_array($g_numbers)) {
foreach ($g_numbers as $number) {
$sms = array(
'from' => 'DummyFrom',
/* Can be up to 11 alphanumeric characters */
'to' => "" . $number . "",
/* The mobile number you want to send to */
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}
?>
This will work because tables values are stored in $people:
if (is_array($people)) {
foreach ($people as $number) {
$sms = array(
'from' => 'DummyFrom',
/* Can be up to 11 alphanumeric characters */
'to' => "" . $number . "",
/* The mobile number you want to send to */
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}

zend multicheckboxes form controller

Merged with multicheckboxes zend form multi populate.
i did do the form with multicheckboxs and it works fine when insert or update but the my problem is how to populate all the multi boxes that is checked form the database this is the code but it doesn't show just one checkbox is checked
$id = (int) $this->_request->getParam('id');
//The incoming request
$request = $this->getRequest();
//initialize form
$form = new Admin_Form_DownFooterTab();
//instance of db
$db = Zend_Db_Table::getDefaultAdapter();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
if (isset($id) && $id != "") {
$gettag = $form->getValue('tag_id');
$gettags = count($gettag);
try {
//shift the orders to
$select = $db->select()->from(array('t' => 'tab'), array('t.id',
't.title',
't.tab_position',
't.order',
't.is_active',
't.is_deleted'))->where('id = ?', $id);
$currentTab = $db->fetchRow($select);
$var3 = array('tab.order' => new Zend_Db_Expr('tab.order - 1'));
$var4 = array('tab.order >= ' . $currentTab['order'], 'is_active=1', 'is_deleted=0', 'tab_position=4');
$db->update('tab', $var3, $var4);
$var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
$var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=4');
$db->update('tab', $var, $var2);
$db->delete('tab_tag', array('tab_id = ?' => $id));
foreach ($gettag as $value) {
$db->insert('tab_tag',
array(
'tag_id' => $value,
'tab_id' => $id
));
}
$db->update('tab', array(
'title' => $form->getValue('title'),
'body' => $form->getValue('body'),
'is_active' => $form->getValue('is_active'),
'banner_link' => $form->getValue('banner_link'),
'tab_path' => $form->getValue('tab_path'),
'link_open' => $form->getValue('link_open'),
'tab_position' => $form->getValue('tab_position'),
'tab_parent' => $form->getValue('tab_parent')
),
array('id =?' => $id));
$this->flash('Tab Updated', 'admin/tab');
} catch (Exception $e) {
$this->flash($e->getMessage(), 'admin/tab');
}
} else {
try {
$formValues = $form->getValues();
$formValues['created_by'] = 1;
$formValues['created_date'] = date('Y/m/d H:i:s');
$formValues['is_deleted'] = 0;
$var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
$var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=4');
$db->update('tab', $var, $var2);
foreach ($gettag as $value) {
$db->insert('tab_tag',
array(
'tag_id' => $value,
'tab_id' => $id
));
}
$db->insert('tab', array(
'title' => $form->getValue('title'),
'body' => $form->getValue('body'),
'is_active' => $form->getValue('is_active'),
'banner_link' => $form->getValue('banner_link'),
'tab_path' => $form->getValue('tab_path'),
'link_open' => $form->getValue('link_open'),
'tab_position' => $form->getValue('tab_position'),
'tab_parent' => $form->getValue('tab_parent')
));
$this->flash('Tab inserted', 'admin/tab');
} catch (Exception $e) {
$this->flash($e->getMessage(), 'admin/tab');
}
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
if (isset($id) && $id != "") {
$values = $db->fetchRow("SELECT * FROM tab WHERE id = ?", $id);
$form->populate($values);
}
$this->view->form = $form;
}
$ddlCat_parent->setMultiOptions($cats);
$this->view->form = $form;
}

Categories