codeigniter query gives error - codeigniter

I am writing this code to get an email from the following query, but it gives me an error:
undefined variable email
It seems that the result generated from that query can't be seen outside of the foreach loop, but I want that email variable. The error is in send_session_close_mail() function:
$qry="select email from end_employee_master where
id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')" ;
$query=$this->db->query($qry);
$num=$query->num_rows();
foreach($query->result() as $row) {
$email=$row->email;
}
Full code listing:
<?php
class Email_model extends CI_Model {
private $config = null;
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('email');
$this->config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.santulan.co.in',
'smtp_port' => 25,
'smtp_user' => 'no.reply#santulan.co.in', // change it to yours
'smtp_pass' => 'Admin#123', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->email->initialize($this->config);
}
public function send_password_reset_mail($new_pass, $email) {
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p>
<p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p>
<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Click here</span></p>
<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p>
<p> </p>
<p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p>
<p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan </span></p>
<p><br />
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: Password Reset Link');
$this->email->message($message_str);
$this->email->send();
}
/**
function to change the password of the team
**/
public function send_password_reset_mail_team($new_pass, $email) {
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p>
<p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p>
<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Click here</span></p>
<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p>
<p> </p>
<p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p>
<p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan </span></p>
<p><br />
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: Password Reset Link');
$this->email->message($message_str);
$this->email->send();
}
/**
* Send mail to Counselor that Conversation has been
* updated by User for the E-Counseling case.
* #param type $data About case ID description etc.
*/
public function set_EC_notify_mail_counselor($data) {
$this->load->model('users');
$userdata = $this->users->get_end_employee_Detail($data['eemp_id']);
$counselordata = $this->users->get_counselor_Detail($data['counseler_id']);
if ($userdata && $counselordata) {
$mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . ".";
$mailBody = '<p>Hi ' . $counselordata->name . ',</p>
<p>Greeting for the day.</p>
<p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] .
' feedback conversation. This reply is from employee ' . $userdata->name . ' ' .
$userdata->lname .
'. Please login to http://www.santulan.co.in to respond this.</p>
<p> </p>
<p><span style="font-weight:normal;">Thanks & Regards,</span></p>
<p><span style="font-weight: normal;">Santulan Support Team</span></p>';
$this->email->initialize($this->config);
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($counselordata->email);
$this->email->subject($mailSubject);
$this->email->message($mailBody);
$this->email->send();
}
}
/**
* Send mail to Counselor that Conversation has been
* updated by User for the E-Counseling case.
* #param type $data About case ID description etc.
*/
public function set_EC_notify_mail_endUser($data) {
$this->load->model('users');
$userdata = $this->users->get_end_employee_Detail($data['eemp_id']);
$counselordata = $this->users->get_counselor_Detail($data['counseler_id']);
if ($userdata && $counselordata) {
$mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . ".";
$mailBody = '<p>Hi ' . $userdata->name . ' ' .
$userdata->lname . ',</p>
<p>Greeting for the day.</p>
<p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] .
' feedback conversation. This reply is from Counselor ' . $counselordata->name .
'. Please login to http://www.santulan.co.in to respond this.</p>
<p> </p>
<p><span style="font-weight:normal;">Thanks & Regards,</span></p>
<p><span style="font-weight: normal;">Santulan Support Team</span></p>';
$this->email->initialize($this->config);
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($counselordata->email);
$this->email->subject($mailSubject);
$this->email->message($mailBody);
$this->email->send();
}
}
public function send_feedback_mail($case_id, $emailID, $fname, $lname) {
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<pre><em><strong>hello $fname end user why you want feedback from me cant you call me or you dont hav'
. ' enough balance in your phone. clik on the link below http://www.santulan/feedback/feedback_form?case_id=EC-12&emp_id=2&c_id</strong></em></pre>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($emailID);
$this->email->subject('Santulan-Feedback Email');
$this->email->message('$message_str');
$email->send();
}
/**public function send_session_details($output) {
$base_url = base_url();
$this->email->initialize($this->config);
$case_id = $output['CaseId'];
$sessionDetail = $output['currentSessionDetails'];
$query = " SELECT email FROM end_employee_master WHERE id=(SELECT eemp_id FROM book_e_counseling_mst WHERE CaseId='$case_id')";
$result = $this->db->query($query);
foreach ($result->result() as $row) {
$mail_id = $row->email;
}
$message_str = '<pre><em><strong>Hello counseler you have new case</strong></em></pre>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Team');
$this->email->to($mail_id);
$this->email->subject('Counselor you have new case come on');
$this->email->message($message_str);
$this->email->send();
}**/
public function send_helpline_registration_mail($gvfcode,$data,$password) {
$base_url = base_url();
$this->email->initialize($this->config);
$email = $data['email'];
$firstname = $data['name'];
$lastname = $data['lname'];
$pass = $password;
$url = 'http://www.santulan.co.in/registration/verification/' . $gvfcode;
$message = "Dear $firstname $lastname, \n " .
'<p dir="ltr" style="color: rgb(34, 34, 34); font-family:Tahoma, Tahoma; font-size: 14 background-color: rgb(255, 255, 255);">
Thank you for reaching out to SANTULAN. Please activate your account by clicking on the below link.</p>
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
<!---<strong>You can take counselling via phone or face 2 face</strong></p>--->
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
<!---<strong>For more details contact or Helpline no.</p>--->
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
<!---<strong>Also you can activate your account by clicking below link</p>--->
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; fon background-color: rgb(255, 255, 255);">
<b>' . $url .'</b></p>
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
Your login id is your email address : ' . $email . '</p>
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
Your password is :
' . $pass . '</p>
<p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
<em>Thank you,<br />
Team Santulan </em></p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to(trim($email));
$this->email->subject('Registration Confirmation');
$this->email->message($message);
$this->email->send();
}
/**
Function to send email form submitted mail for E-counseling
**/
public function send_mail_to_user($email)
{
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p> Hello There'.
'<br>'.
'<br>We have received your request. We will be in touch shortly'.
'<br>'.
'<br>Team Santulan
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: You filled a form for E-Counseling');
$this->email->message($message_str);
$this->email->send();
}
/**
Function to send email form submitted mail for Telephonic-counseling
**/
public function send_mail_to_tele_user($email)
{
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p> Hello There'.
'<br>'.
'<br>We have received your request. We will be in touch shortly'.
'<br>'.
'<br>Team Santulan
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: Your Counseling Appointment');
$this->email->message($message_str);
$this->email->send();
}
/**
Function to send email form submitted mail for F to F-counseling
**/
public function send_mail_to_ftof_user($email)
{
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p> Hello There'.
'<br>We have received your request. We will be in touch shortly'.
'<br>'.
'<br>Team Santulan
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: Your Counseling Appointment');
$this->email->message($message_str);
$this->email->send();
}
/**
Function to send email form submitted mail for video - counseling
**/
public function send_mail_to_video_user($email)
{
$base_url = base_url();
$this->email->initialize($this->config);
$message_str ='<p> Hello There'.
'<br>'.
'<br>We have received your request. We will be in touch shortly'.
'<br>'.
'<br>Team Santulan
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject('Message From Santulan: Your Counseling Appointment');
$this->email->message($message_str);
$this->email->send();
}
/**
public function send_mail_fs()
{
$userid = $this->session->all_userdata();
$email = $userid['logged_in']['email'];
$base_url = base_url();
$this->email->initialize($this->config);
$message_str = '<p>Hello There,<br>
You have new case for assignment,please login and assighn it to counselor.
</p>';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is first support mail");
$this->email->message($message_str);
$this->email->send();
}
**/
public function send_counselor_mail($email)
{
$this->email->initialize($this->config);
$message_str = 'Hello this is mail for counselor testing';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to("hemantrandivehr#gmail.com");
$this->email->subject("This is first support mail");
$this->email->message($message_str);
$this->email->send();
}
/**
Function to send mail to enduser thatb session is closed
**/
public function send_session_close_mail($session_id,$c_type,$cid)
{
//$url = 'https://www.surveymonkey.com/r/?sm=s8ma655VB3Jd39QMaNl2YPaVWsbL3XPHrBW6ryEbhkGruBuQ8SLyNsX3hY6gwgopkuIJdbQy0GrI%2fPd77ydWOSP4R%2fOxaHLr52uARCuMiLg%3d';
if($c_type=='E_Counseling')
{
$qry="select email from end_employee_master where id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')" ;
$query=$this->db->query($qry);
$num=$query->num_rows();
foreach($query->result() as $row)
{
$email=$row->email;
}
$this->email->initialize($this->config);
$message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
}
if($c_type=='Telephone_Counseling')
{
$qry="SELECT email FROM book_tele_counseling_mstr WHERE CaseId like 'TC-" . $cid . "'";
$query=$this->db->query($qry);
$num=$query->num_rows();
foreach($query->result() as $row)
{
//$eemp_id=$row->eemp_id;
$email=$row->email;
}
$this->email->initialize($this->config);
$message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
}
if($c_type=='F2F_Counseling')
{
$qry="SELECT email FROM book_ff_counseling_mstr WHERE CaseId like 'FC-" . $cid . "'";
$query=$this->db->query($qry);
$num=$query->num_rows();
foreach($query->result() as $row)
{
//$eemp_id=$row->eemp_id;
$email=$row->email;
}
$this->email->initialize($this->config);
$message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
}
if($c_type=='Video_Counseling')
{
$qry="SELECT email FROM book_vedio_counseling_mstr WHERE CaseId like 'VC-" . $cid . "'";
$query=$this->db->query($qry);
$num=$query->num_rows();
foreach($query->result() as $row)
{
//$eemp_id=$row->eemp_id;
$email=$row->email;
}
$this->email->initialize($this->config);
$message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
}
}
}

As per your comment 339 and 340 line number it showing error,its for email variable there in send_session_close_mail()
Next is what your code :
foreach($query->result() as $row)
{
$email=$row->email;
}
$this->email->initialize($this->config);
$message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
I come to know that you want to send email to multiple email-ids as you have foreach loop. and in that for loop variable email is declared.
I suggest you to put all sendding email code in that loop only as follow and try once
foreach($query->result() as $row)
{
$email=$row->email;
$this->email->initialize($this->config);
$message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link Click Here ';
$this->email->from('no.reply#santulan.co.in', 'Santulan Suport Team');
$this->email->to($email);
$this->email->subject("This is mail from counselor");
$this->email->message($message_str);
$this->email->send();
}
This may solve your issue.

Related

(Codeigniter) Echo result in view automatic insert to database

I want echo from if/else conditions (NEW, ALERT, ACTIVE, EXPIRED) automatic input to tr_status column in database. What should I do?
column picture phpmyadmin
<td>
<?php
$today = Date("Y-m-d");
$months = Date("Y-m-d", strtotime('+180 days'));
if ($t->tr_no == NULL) {
echo '<span style="color: #20B2AA; font-weight: bold; ">NEW</span>';
}
elseif ($t->tr_exp <= $today) {
echo '<span style=" color: red; font-weight: bold; ">EXPIRED</span>';
}
elseif ($t->tr_exp <= $months) {
echo '<span style="font-weight: bold; color: ORANGE;">ALERT</span>';
}
else {
echo '<span style="font-weight: bold; color: #4DBE24;">ACTIVE</span>';
}
?>
</td>
you need to create a function inside the contoller before load the view file
example :
$today = Date("Y-m-d");
$months = Date("Y-m-d", strtotime('+180 days'));
if ($t->tr_no == NULL) {
$object = array('tr_status' => 'NEW');
}elseif ($t->tr_exp <= $today) {
$object = array('tr_status' => 'EXPIRED');
} else {
$object = array('tr_status' => 'ACTIVE');
}
$this->db->insert('Table', $object);

How to check if data in a database is true? - Not using Session in CodeIgniter

I'm using CodeIgniter and I've got a function to insert an email address and a code into a database.
I now want the user to post that code and if it is correct, delete it, and if it is not correct, to give the user another try.
I've edited the original coding.
Email Controller - I've deleted reference to sessions and commented out the sending of the email because I'm only testing in localhost. The Email function works good. After posting the Email function I open the database and copy the code which must be correct.
Code Controller - I've deleted reference to sessions. And I now have an email text box in code view, which BTW automatically inserts the email address. I then paste the code into the code text box.
However, despite the code being correct the view('codeincorrect') is selected instead of view('username').
Can somebody tell me what is wrong?
Email Controller
class Email extends CI_Controller
{
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
/*
$this->load->library('email');
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>');
$this->email->to('$email');
$this->email->subject('Code.');
$this->email->message('Select & Copy this code, then return to the website. - ','$code');
$this->email->send();
*/
$this->load->view('code');
}
}
}
Email Model
class Email_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function insert_email($email, $code)
{
$data = array('email_address' => $email,'pass_word' => $code);
$this->db->insert('tbl_members', $data);
return $this->db->insert_id();
}
}
Code Controller
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$email = $this->input->post('email');
$code = $this->input->post('code');
$result = $this->code_model->find_code($email, $code);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
Code Model
class Code_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function find_code($email, $code)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result())
{
return $this->db->delete('pass_word', $code);
}
}
}
This is the coding in the code view, which maybe causing the problem;
<style type="text/css"> .email-address { position: fixed; width: 100%; text-align: center; top: 30%; } </style>
<div class="email-address">
<input type="text" name="email" value="<?php echo set_value('email'); ?>" style="width: 18%; height: 5mm"; />
<style type="text/css"> .code { position: fixed; width: 100%; text-align: center; top: 55%; } </style>
<div class="code">
<input type="email" class="form-control" name="code" style="width: 15mm; height: 5mm"; />
</div>
<?php echo form_open('code'); ?>
<style type="text/css"> .submit { position: fixed; width: 100%; text-align: center; top: 65%; } </style>
<div class="submit">
<input type="submit" class="btn btn-primary" value="Submit" />
</form></div>
Please try it.
In Controller
public function index()
{
$this->load->model('Code_model', 'code_model');
$code = $this->input->post('code');
// Need to email here.
$email= $this->input->post('email');
$result = $this->code_model->find_code($code,$email);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
In Model
public function find_code($code,$email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result()) {
$this->db->delete('pass_word', $code);
}
}
So, your Controller calls the Model correctly but you are not checking the Model function and you are not sending the email field.
So this should be correct:
Controller:
public function index()
{
$this->load->model('Code_model', 'code_model');
$code = $this->input->post('code');
$email= $this->input->post('email');
if ($this->code_model->find_code($code, $email)) {
$this->load->view('username');
} else {
$this->load->view('codeincorrect');
}
}
Model:
public function find_code($code, $email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members')->result();
if ($code->num_rows() >= 1) {
$this->db->delete('pass_word', $code);
}
}
Note:
If what you are trying to do is a password login, that's not how you should do it. Please see this for example: http://www.iluv2code.com/login-with-codeigniter-php.html

how to create form for multple image upload in codeigniter

i have created form for multiple image upload.but not working that form.only one image uploading..i want multiple images are to be upload to folder and save image name in database..
My View File
<html>
<head>
<title>Product Upload</title>
<style>
#container
{
width:750px;
margin:0 auto;
//border:5px solid #000000;
}
#container form input[type="text"] {
height:30px;
}
</style>
</head>
<body>
<div id="container" align="center">
<form name="product" action="<?php echo base_url;?>admin/login/upload" method="POST" enctype="multipart/form-data" class="form-horizontal">
<table>
<h3>Add New Product</h3>
<tr><td>Categories</td><td><select name="catid"><option>Categories</option>
<?php if(isset($category_details))
{foreach($category_details as $keys=>$values){ ?>
<option value="<?php echo $values['cat_id'];?>"><?php echo $values['cat_name'];?></option>
<?php }
}?>
</select></td></tr>
<tr>
<td>Product Name:</td><td><input type="text" name="pname"></td></tr>
<tr><td><input type="file" multiple="true" name="userfile" size="20" /></td></tr>
<tr><td><br>Product Image:</td><td><br><input type="file" name="pimage[]" id="pimage" multiple></td></tr>
<tr><td><br>Description:</td><td><br><textarea name="pdescription"></textarea></td></tr>
<tr><td><br>Price:</td><td><br><input type="text" name="price"></td></tr>
<tr><td colspan="2" align="center"><br><input type="submit" name="submit" value="ADD" class="btn btn-primary"></td></tr>
</table>
</form>
</div>
</body>
</html>
My Controller File
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see http://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('admin/category_model');
$this->load->model('admin/loginauth_model');
$this->load->model('login_model');
$this->load->library('session');
$this->load->helper('url');
$this->load->helper('cookie');
$this->load->library('encrypt');
$this->load->library('image_CRUD');
}
public function index()
{
$this->load->view('admin/login');
}
public function loadproduct()
{
$category_details=$this->category_model->getCategoryDetails();
$outputdata["category_details"]=$category_details;
$this->load->view('admin/product',$outputdata);
}
public function loginAuth()
{
$this->form_validation->set_rules('email','Enter Email','required|trim|max_length[50]|xss_clean');
$this->form_validation->set_rules('password','Enter your Password','required|trim|max_length[50]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/login');
}
else
{
$username=$_POST['email'];
$password=$_POST['password'];
$user_details=$this->loginauth_model->logincheck($username,$password);
//print_r($checkauth);
if($user_details)
{
if($this->session->userdata('adminusername'))
{
$adminusername=$this->session->userdata('adminusername');
$outputdata['username']=$adminusername;
}
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
$this->load->view('admin/dashboard',$outputdata);
}
}
}
public function category()
{
//$this->load->view('admin/category');
$this->form_validation->set_rules('cat_name','category name','required|trim|max_length[50]|xss_clean');
$this->form_validation->set_rules('cat_desc','category description','required|trim|max_length[50]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/category');
}
else
{
$addcategory=$this->category_model->addcategory($_POST);
if($addcategory)
{
//**************************pending
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
//print_r($outputdata);
$this->load->view('admin/categorylist',$outputdata);
}
}
}
public function categorylist()
{
//echo image_url;
$category_details=$this->category_model->getCategoryDetails();
$outputdata['category_details']=$category_details;
$outputdata['image_url']=image_url;
$this->load->view('admin/categorylist',$outputdata);
$this->load->view('admin/category');
}
public function userdetails()
{
$user_details=$this->login_model->userdetails();
$outputdata['user_details']=$user_details;
$this->load->view('admin/userdetails',$outputdata);
}
public function upload()
{
$productname=$_POST["pname"];
$description=$_POST["pdescription"];
$price=$_POST["price"];
$catid=$_POST["catid"];
$name_array = array();
echo $count = count($_FILES['pimage']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++) {
$_FILES['pimage']['name']=$value['name'][$s];
$_FILES['pimage']['type'] = $value['type'][$s];
$_FILES['pimage']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['pimage']['error'] = $value['error'][$s];
$_FILES['pimage']['size'] = $value['size'][$s];
$config['upload_path'] = FCPATH.'img/product_uploads/original/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|GIF|PNG|JPG|JPEG';
$config['max_size'] = '100';
$config['max_width'] = '150';
$config['max_height'] = '180';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
//$products=$this->category_model->addproduct($catid,$productname,$description,$imagename,$imagesize,$price,$path);
}
$names= implode(',', $name_array);
/* $this->load->database();
$db_data = array('id'=> NULL,
'name'=> $names);
$this->db->insert('testtable',$db_data);
*/ print_r($names);
//echo FCPATH;
//$productname=$_POST["pname"];
// $description=$_POST["pdescription"];
// $price=$_POST["price"];
//$catid=$_POST["catid"];
// $path = FCPATH.'img/product_uploads/original/';
// $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP","PNG");
// if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
// $imagename = $_FILES['pimage']['name'];
// $imagesize = $_FILES['pimage']['size'];
// list($txt, $ext) = explode(".", $imagename);
//$products=$this->category_model->addproduct($catid,$productname,$description,$imagename,$imagesize,$price,$path);
//print_r($products);
// $tmp = $_FILES['pimage']['tmp_name'];
//if(move_uploaded_file($tmp, $path.$imagename)) {
// $product_details=$this->category_model->getProductDetails();
//print_r($product_details);
//if(isset($products)){
//echo "aa";
// $this->loadproduct();
//}
// }
//else
// {
//echo "Image Upload Failed.";
//}
}
public function logout()
{
$newdata = array(
'adminuser_id' =>'',
'adminusername' =>'',
'adminemail' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata);
$this->session->sess_destroy();
$this->index();
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
You can't just add a multiple attrinbute to <input type="file" />, that's not going to work.
You'll have to use a third-party module/plugin, like Uploadify, to get this functionality running.
You could also check this tutorial on how to integrate Uploadify in CodeIgniter (although I can't see anything CodeIgniterish in your code, but you still tagged the question as CI relevant)
a) Instead of writing this <input type="file" multiple="true" name="userfile" size="20" /> write <input type="file" name="userfile[]" size="20" />
b) Inside your controller you can do something like this:
$files = $_FILES;
$count = count($_FILES['userfile']['name']);
for($i=0; $i<$count; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($config);
$this->upload->do_upload();
$image_data = $this->upload->data();
}
Use this to open your upload form :
echo form_open_multipart('admin/do_upload');
After put one or more :
<input type="file" name="name" size="20" />
And use a function like that :
public function do_upload() {
$config['upload_path'] = './assets/images/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/images', $error);
} else {
$data = array('upload_data' => $this->upload->data());
}
}

How can I center image gallery within my div?

I am trying to center a PHP generated image gallery horizontally on the page. It seems I have tried everything but nothing works! Here is a link to the page: http://rabbittattoo.com/?gallery=gallery
Here is the html that for the gallery:
<!-- Begin content -->
<div id="content_wrapper"><div class="inner">
<!-- Begin main content -->
<div id="gallery_wrapper" class="inner_wrapper portfolio"><div class="standard_wrapper small"><br class="clear"></br><br></br>
<!-- Begin portfolio content -->
<div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth last" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><br class="clear"></br><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><div class="one_fourth last" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div><br class="clear"></br><div class="one_fourth" style="margin-right:24px;margin-bottom:24px;margin-top:-20px"></div></div>
<!-- End main content -->
And the associated CSS:
#content_wrapper .inner .inner_wrapper.portfolio {
padding: 10px 0px 0px;
position: relative;
left: -10px;
}
#content_wrapper .inner .inner_wrapper {
margin-top: 28px;
}
#content_wrapper .inner .inner_wrapper {
width: 91%;
margin-left: 5.5%;
padding: 10px 0px 25px;
background: none repeat scroll 0% 0% transparent;
margin-top: 30px;
}
#gallery_wrapper {
width: 100%;
margin: 0px auto;
}
And the PHP:
$pp_gallery_style = get_option('pp_gallery_style');
if($pp_gallery_style == 'f')
{
include_once(TEMPLATEPATH.'/gallery-f.php');
exit;
}
if(!isset($hide_header) OR !$hide_header)
{
get_header();
}
$caption_class = "page_caption";
$portfolio_sets_query = '';
$custom_title = '';
if(!empty($term))
{
$portfolio_sets_query.= $term;
$obj_term = get_term_by('slug', $term, 'photos_galleries');
$custom_title = $obj_term->name;
}
else
{
$custom_title = get_the_title();
}
/**
* Get Current page object
**/
$page = get_page($post->ID);
/**
* Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
$current_page_id = $page->ID;
}
if(!isset($hide_header) OR !$hide_header)
{
?>
<div class="wrapper_shadow"></div>
<div class="page_caption">
<div class="caption_inner">
<div class="caption_header">
<h1 class="cufon"><?php echo the_title(); ?></h1>
</div>
</div>
</div>
</div>
<!-- Begin content -->
<div id="content_wrapper">
<div class="inner">
<!-- Begin main content -->
<div id="gallery_wrapper" class="inner_wrapper portfolio">
<div class="standard_wrapper small">
<br class="clear"/><br/>
<?php
}
else
{
echo '<br class="clear"/>';
}
?>
<?php echo do_shortcode(html_entity_decode($page->post_content)); ?>
<!-- Begin portfolio content -->
<?php
$menu_sets_query = '';
$portfolio_items = 0;
$portfolio_sort = get_option('pp_gallery_sort');
if(empty($portfolio_sort))
{
$portfolio_sort = 'DESC';
}
$args = array(
'post_type' => 'attachment',
'numberposts' => $portfolio_items,
'post_status' => null,
'post_parent' => $post->ID,
'order' => $portfolio_sort,
'orderby' => 'date',
);
$all_photo_arr = get_posts( $args );
if(isset($all_photo_arr) && !empty($all_photo_arr))
{
?>
<?php
foreach($all_photo_arr as $key => $portfolio_item)
{
$image_url = '';
if(!empty($portfolio_item->guid))
{
$image_id = $portfolio_item->ID;
$image_url[0] = $portfolio_item->guid;
}
$last_class = '';
$line_break = '';
if(($key+1) % 4 == 0)
{
$last_class = ' last';
if(isset($page_photo_arr[$key+1]))
{
$line_break = '<br class="clear"/><br/>';
}
else
{
$line_break = '<br class="clear"/>';
}
}
?>
<div class="one_fourth<?php echo $last_class?>" style="margin-right:24px;margin-bottom:24px;margin-top:-20px">
<a title="<?php echo $portfolio_item->post_title?>" href="<?php echo $image_url[0]?>" class="one_fourth_img" rel="gallery" href="<?php echo $image_url[0]?>">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/timthumb.php?src=<?php echo $image_url[0]?>&h=370&w=350&zc=1" alt=""/>
</a>
</div>
<?php
echo $line_break;
}
//End foreach loop
?>
<?php
}
//End if have portfolio items
?>
</div>
<!-- End main content -->
<br class="clear"/><br/>
</div>
<?php
if(!isset($hide_header) OR !$hide_header)
{
?>
</div>
<!-- End content -->
<?php get_footer(); ?>
<?php
}
?>
I have tried centering by adjusting the margins but is had no effect. Can anyone tell me what I am doing wrong? Thank you in advance for your help!

ajax json form submit

I have this code for form submit:
index.php
<html>
<head>
<title>My Form</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#myForm").submit(function(){
var tvyalner = $("#myForm").serialize();
$.ajax({
type: "POST",
url: "postForm.ajax.php",
data: tvyalner,
dataType: "json",
success: function(data){
$("#formResponse").removeClass('error');
$("#formResponse").addClass(data.status);
$("#formResponse").html(data.message);
if(data.status === 'success'){$("#myForm table").hide();}
},
error: function(){
$("#formResponse").removeClass('success');
$("#formResponse").addClass('error');
$("#formResponse").html("There was an error submitting the form. Please try again.");
}
});
//make sure the form doens't post
return false;
});
});
</script>
<style type="text/css">
.success{
border: 2px solid #009400;
background: #B3FFB3;
color: #555;
font-weight: bold;
}
.error{
border: 2px solid #DE001A;
background: #FFA8B3;
color: #000;
font-weight: bold;
}
</style>
</head>
<body>
<div class="mfm">
<form id="myForm" name="myForm" method="post" action="" style="margin: 0 auto; width: 300px;">
<div id="formResponse"></div>
<table>
<tr><td>Name:</td><td><input name="name" type="text" value=""></td></tr>
<tr><td>Email:</td><td><input name="email" type="text" value=""></td></tr>
<tr><td>Message:</td><td><textarea name="message" rows="5" cols="20"></textarea></td></tr>
<tr><td> </td><td><input type="submit" name="submitForm" value="Submit Form"></td></tr>
</table>
</form>
</div>
</body>
</html>
postForm.ajax.php
<?php
//function to validate the email address
//returns false if email is invalid
function checkEmail($email){
if(eregi("^[a-zA-Z0-9_]+#[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)){
return FALSE;
}
list($Username, $Domain) = split("#",$email);
if(#getmxrr($Domain, $MXHost)){
return TRUE;
} else {
if(#fsockopen($Domain, 25, $errno, $errstr, 30)){
return TRUE;
} else {
return FALSE;
}
}
}
//response array with status code and message
$response_array = array();
//validate the post form
//check the name field
if(empty($_POST['name'])){
//set the response
$response_array['status'] = 'error';
$response_array['message'] = 'Name is blank';
//check the email field
} elseif(!checkEmail($_POST['email'])) {
//set the response
$response_array['status'] = 'error';
$response_array['message'] = 'Email is blank or invalid';
//check the message field
} elseif(empty($_POST['message'])) {
//set the response
$response_array['status'] = 'error';
$response_array['message'] = 'Message is blank';
//form validated. send email
} else {
//send the email
$body = $_POST['name'] . " sent you a message\n";
$body .= "Details:\n\n" . $_POST['message'];
mail($_POST['email'], "SUBJECT LINE", $body);
//set the response
$response_array['status'] = 'success';
$response_array['message'] = 'Email sent!';
}
echo json_encode($response_array);
?>
After first submit displaying:
Name is blank.
Filling field and submitting again. displaying
There was an error submitting the form. Please try again.
and that's all.
Code not working in localhost.
What is the problem?
I suggest using this error-function to see what the error is:
$.ajax({
/* ... */
error: function(jqXHR, textStatus, errorThrown){
console.log(errorThrown); // Or use alert()
console.log(textStatus);
$("#formResponse").removeClass('success');
$("#formResponse").addClass('error');
$("#formResponse").html("There was an error submitting the form. Please try again.");
}
});

Resources