Im having trouble loading an array into the templatevars variable
It seems to be unidentified everytime i run it
and it doesnt seem to be putting the array into the variable
I would appreciate any help i can get with this Thanks
Here is the code I'm using
<?php
require '../template.php';
$title = 'List';
if (isset($_SESSION['login']) && $_SESSION['login'] == true) {
if (isset($_POST['submit'])) {
$jokes = find($pdo, 'jokes');
$applications = $pdo->prepare('SELECT count(*) as count FROM applications WHERE jokeId = :jokeId');
$applications->execute(['jokeId' => $jokes['id']]);
$applicantNumber = $applications->fetch();
$categoryList = $pdo->prepare('SELECT * FROM category WHERE id = :id');
$values = [
'id' => $jokes['categoryid']
];
$categoryList->execute($values);
$categoryName = $categoryList->fetch();
$filterCity = find($pdo, 'jokes');
$templateVars = array(
'jokes' => $jokes,
'category' => $categoryList,
'applications' => $applications,
'jokes' => $filterCity,
'categoryList' => $categoryName,
'applications' => $applicantNumber
);
} else {
$jokes = find($pdo, 'jokes');
$output = loadTemplate('../Templates/jobListing.html.php', $templateVars);
}
} else {
$output = loadTemplate('../Templates/login.html.php', []);
}
require '../Templates/layout.html.php';
Related
I saw the similar questions, but it has not helped me. I am trying to fetch message. I need full message with all parts, headers, attachments.
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->fullText();
/** #var Horde_Imap_Client_Fetch_Results $mail */
$results = $client->fetch('INBOX', $fetchQuery, ['ids' => new Horde_Imap_Client_Ids(11632)]);
var_dump($results->first()->getEnvelope()->subject);
I tried a lot of variants. But I can't get any info about message. The subject is empty string. I am sure, such mail with that uid exists, I got this uid with Horde also.
Try the code mentioned below. $results array has all the items you need.
$uids = new \Horde_Imap_Client_Ids($thread_uids);
$query = new \Horde_Imap_Client_Fetch_Query();
$query->envelope();
$query->structure();
$messages = $oClient->fetch($mailbox, $query, array('ids' => $uids));
$results = [];
foreach($messages as $message){
$envelope = $message->getEnvelope();
$structure = $message->getStructure();
$msghdr = new StdClass;
$msghdr->recipients = $envelope->to->bare_addresses;
$msghdr->senders = $envelope->from->bare_addresses;
$msghdr->cc = $envelope->cc->bare_addresses;
$msghdr->bcc = $envelope->bcc->bare_addresses;
$msghdr->subject = $envelope->subject;
$msghdr->timestamp = $envelope->date->getTimestamp();
$query = new Horde_Imap_Client_Fetch_Query();
$query->fullText();
$typemap = $structure->contentTypeMap();
foreach ($typemap as $part => $type) {
// The body of the part - attempt to decode it on the server.
$query->bodyPart($part, array(
'decode' => true,
'peek' => true,
));
$query->bodyPartSize($part);
}
$id = new Horde_Imap_Client_Ids($message->getUid());
$messagedata = $oClient->fetch($mailbox, $query, array('ids' => $id))->first();
$msgdata = new StdClass;
$msgdata->id = $id;
$msgdata->contentplain = '';
$msgdata->contenthtml = '';
$msgdata->attachments = array(
'inline' => array(),
'attachment' => array(),
);
$plainpartid = $structure->findBody('plain');
$htmlpartid = $structure->findBody('html');
foreach ($typemap as $part => $type) {
// Get the message data from the body part, and combine it with the structure to give a fully-formed output.
$stream = $messagedata->getBodyPart($part, true);
$partdata = $structure->getPart($part);
$partdata->setContents($stream, array('usestream' => true));
if ($part == $plainpartid) {
$msgdata->contentplain = $partdata->getContents();
} else if ($part == $htmlpartid) {
$msgdata->contenthtml = $partdata->getContents();
} else if ($filename = $partdata->getName($part)) {
$disposition = $partdata->getDisposition();
$disposition = ($disposition == 'inline') ? 'inline' : 'attachment';
$attachment = new StdClass;
$attachment->name = $filename;
$attachment->type = $partdata->getType();
$attachment->content = $partdata->getContents();
$attachment->size = strlen($attachment->content);
$msgdata->attachments[$disposition][] = $attachment;
}
}
$data = [
'uid' => implode("",$id->ids),
'from' => implode(",",$msghdr->senders),
'cc' => implode(",",$msghdr->cc),
'bcc' => implode(",",$msghdr->bcc),
'to' => implode(",",$msghdr->recipients),
'date' => $msghdr->timestamp,
'subject' => $envelope->subject,
'hasAttachments' => $structure->getDisposition(),
'folder' => $mailbox,
'messageId' => $envelope->message_id,
'attachment' => $msgdata->attachments
];
$data['body'] = empty($msgdata->contenthtml) ? $msgdata->contenttext: $msgdata->contenthtml;
array_push($results,$data);
}
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->fullText();
/** #var Horde_Imap_Client_Fetch_Results $mail */
$results = $client->fetch('INBOX', $fetchQuery, ['ids' => new Horde_Imap_Client_Ids(11632)]);
var_dump($results->first()->getFullMsg());
In this code filter, search and pagination not functioning i have tried myself but it didn't work so please check the code give me any solution or any reference regarding to this query. Even any related to this code files or docs it will be helpful for me to pursue the concept
<?php
mb_internal_encoding('UTF-8');
$database = 'test';
$collection = 'user';
/**
* MongoDB connection
*/
try{
// Connecting to server
$m = new MongoClient( );
}catch(MongoConnectionException $connectionException){
print $connectionException;
exit;
}
$m_collection = $m->$database->$collection;
$input = $fields = $totalRecords = $data = array();
$input = & $_REQUEST;
$fields = array('id', 'name', 'email', 'gender,');
// Input method (use $_GET, $_POST or $_REQUEST)
/**
* Handle requested DataProps
*/
// Number of columns being displayed (useful for getting individual column search info)
$iColumns = & $input['iColumns'];
// Get mDataProp values assigned for each table column
$dataProps = array();
for ($i = 0; $i < $iColumns; $i++) {
$var = 'mDataProp_'.$i;
if (!empty($input[$var]) && $input[$var] != 'null') {
$dataProps[$i] = $input[$var];
}
}
$searchTermsAny = array();
$searchTermsAll = array();
if ( !empty($input['sSearch']) ) {
$sSearch = $input['sSearch'];
for ( $i=0 ; $i < $iColumns ; $i++ ) {
if ($input['bSearchable_'.$i] == 'true') {
if ($input['bRegex'] == 'true') {
$sRegex = str_replace('/', '\/', $sSearch);
} else {
$sRegex = preg_quote($sSearch, '/');
}
$searchTermsAny[] = array(
$dataProps[$i] => new MongoRegex( '/'.$sRegex.'/i' )
);
}
}
}
// Individual column filtering
for ( $i=0 ; $i < $iColumns ; $i++ ) {
if ( $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
if ($input['bRegex_'.$i] == 'true') {
$sRegex = str_replace('/', '\/', $input['sSearch_'.$i]);
} else {
$sRegex = preg_quote($input['sSearch_'.$i], '/');
}
$searchTermsAll[ $dataProps[$i] ] = new MongoRegex( '/'.$sRegex.'/i' );
}
}
$searchTerms = $searchTermsAll;
if (!empty($searchTermsAny)) {
$searchTerms['$or'] = $searchTermsAny;
}
$totalRecords =$m_collection->count();
$cursor = $m_collection->find($searchTerms, $fields);
/**
* Paging
*/
if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
$cursor->limit( $input['iDisplayLength'] )->skip( $input['iDisplayStart'] );
}
/**
* Ordering
*/
if ( isset($input['iSortCol_0']) ) {
$sort_fields = array();
for ( $i=0 ; $i<intval( $input['iSortingCols'] ) ; $i++ ) {
if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
$field = $dataProps[ intval( $input['iSortCol_'.$i] ) ];
$order = ( $input['sSortDir_'.$i]=='desc' ? -1 : 1 );
$sort_fields[$field] = $order;
}
}
$cursor->sort($sort_fields);
}
foreach ( $cursor as $doc )
{ $name = ''.$doc['name'].'';
$data[] = array($name, $doc['email'], $doc['gender]);
}
/**
* Output
*/
$json_data = array(
"draw"=> intval( $input['draw'] ),
"recordsTotal" =>intval ($totalRecords),
"recordsFiltered" => intval($totalRecords),
"data" => $data
);
echo json_encode( $json_data );
And also i need to Join two tables as given below.
Table 1
Table 2
I am doing it like:
$('#datatable_emp_details').dataTable({
"sServerMethod": "POST",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "get_data.php"
});
get_data.php:
<?php
$mongo = new MongoClient();
$database = $mongo->selectDb('dbtest');
$collection = $database->selectCollection('empDetails');
$skip = (int)$_REQUEST['iDisplayStart'];
$limit = (int)$_REQUEST['iDisplayLength'];
$search = $_REQUEST['sSearch'];
$sortIndex = $_REQUEST['iSortCol_0'];
$sortArray = array('emp_id', 'first_name', 'last_name', 'position', 'email', 'office', 'start_date', 'age', 'salary', 'projects'
);
$sortByCol = $sortArray[$sortIndex];
$sortTypeTxt= $_REQUEST['sSortDir_0']; // asc/desc
$sortType = -1;
if( $sortTypeTxt == 'asc' )
{
$sortType = 1;
}
if( $search != '' )
{
$condtion = array(
'$or' => array(
array('emp_id' => $search),
array('first_name'=> new MongoRegex('/'. $search .'/i')), // i for case insensitive
array('last_name' => new MongoRegex('/'. $search .'/i')),
array('position' => new MongoRegex('/'. $search .'/i')),
array('email' => new MongoRegex('/'. $search .'/i')),
array('office' => new MongoRegex('/'. $search .'/i')),
array('start_date'=> new MongoRegex('/'. $search .'/i')),
array('age' => new MongoRegex('/'. $search .'/i')),
array('salary' => new MongoRegex('/'. $search .'/i')),
array('projects' => new MongoRegex('/'. $search .'/i'))
)
);
$resultSet = $collection->find($condtion)->limit($limit)->skip($skip)->sort(array($sortByCol => $sortType));
}
else
{
$resultSet = $collection->find()->limit($limit)->skip($skip)->sort(array($sortByCol => $sortType))->sort(array($sortByCol => $sortType));
}
$data = array();
if( count( $resultSet ) > 0 )
{
foreach ($resultSet as $document)
{
$data[] = $document;
}
}
$resultSet = $collection->find();
$iTotal = count($resultSet);
$rec = array(
'iTotalRecords' => $iTotal,
'iTotalDisplayRecords' => $iTotal,
'aaData' => array()
);
$k=0;
if (isset($data) && is_array($data)) {
foreach ($data as $item) {
$rec['aaData'][$k] = array(
0 => $item['emp_id'],
1 => $item['first_name'],
2 => $item['last_name'],
3 => $item['position'],
4 => $item['email'],
5 => $item['office'],
6 => $item['start_date'],
7 => $item['age'],
8 => $item['salary'],
9 => $item['projects'],
10 => 'Edit | Delete'
);
$k++;
}
}
echo json_encode($rec);
exit;
?>
Github repository link
My multidimensional associative array :
$search_cookies = array(
"type_catalog" => $type_array,
"size_catalog" => $size_array,
"color_catalog" => $color_array,
);
I need to do that :
$search_cookies = array(
if(isset($type_array){
"type_catalog" => $type_array,
}
elseif(isset($size_array)){
"size_catalog" => $size_array,
}
elseif(isset($color_array)){
"color_catalog" => $color_array,
}
);
Here is the entire code if you think it must be some other way :
$first_array = array('t-1', 's-32', 't-2', 's-36');
function removeLetters($row){
return preg_replace("/[^0-9,.]/", "", $row);
}
foreach($first_array as $row){
$exp_key = explode('-', $row);
if($exp_key[0] == 't'){
$type_array[] = removeLetters($row);
}
if($exp_key[0] == 's'){
$size_array[] = removeLetters($row);
}
if($exp_key[0] == 'c'){
$color_array[] = removeLetters($row);
}
}
$search_cookies = array(
"type_catalog" => $type_array,
"size_catalog" => $size_array,
"color_catalog" => $color_array,
);
you can try this:
$search_cookies = array();
if(isset($type_array)){
$search_cookies["type_catalog"] = $type_array;
}
if(isset($size_array)){
$search_cookies["size_catalog"] = $size_array;
}
if(isset($color_array)){
$search_cookies["color_catalog"] = $color_array;
}
This is in my model.. it says Object of class CI_DB_mysql_result could not be converted to int.. the problem is in the select_max('id');
and it always result to 1. Please help i'm new to codeigniter
public function addEstablishment()
{
$capacity = $this->input->post('capacity');
$name = $this->input->post('name');
$curfew = $this->input->post('curfew');
$price = $this->input->post('price');
$gender = $this->input->post('gender');
$type = $this->input->post('type');
$this->db->select_max('id');
$result = $this->db->get('establishment');
$query = $result + 1;
$owner = $this->session->userdata('id');
$data = array(
'id' => $query,
'name' => $name ,
'capacity' => $capacity ,
'curfew' => $curfew ,
'gender' => $gender ,
'type' => $type ,
'owner' => $owner
);
if($this->db->insert('establishment', $data))
{
echo "Successfully added";
}
}
You have not get max ID in result, please try this way
change
$this->db->select_max('id');
$result = $this->db->get('establishment');
to
$this->db->select_max('id');
$result = $this->db->get('establishment')->row()->id;
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;
}