i am trying to change the login button on my page to a logout button when someone is logged in.
$logged_in = $this->session->userdata('logged_in');
if ($logged_in) {
$data['Lbutton'] = '<div id="login">
<button class="login3"><?php echo anchor("pages/logout", "Logout"); ?></button>
</div>';
} else {
$data['Lbutton'] = '<div id="login">
<button class="login3"><a href= <?php echo base_url()?>index.php/login>login</a> </button>
</div>';
}
and this is my view:
<?php echo $Lbutton ?>
This is Answer:
if ($logged_in)
{
$data['Lbutton'] = '<div id="login">
<button class="login3">'.anchor("pages/logout", "Logout").'</button>
</div>';
}
else
{
$data['Lbutton'] = '<div id="login">
<button class="login3"><a href="'.base_url().'index.php/login" >login</a> </button>
</div>';
}
Related
So, I am making a slideshow inside a modal. The idea is when user clicks "Slideshow", a modal will popup showing a slideshow of images. However when I click next button to view the next image, the modal suddenly closes. I tried putting the code to disable any external or button clicks but it still closes.
here is the code:
<button type="button" id="slide" class="btn btn-primary" data-toggle="modal" data-target="#mySlider">Persembahan Slaid</button><br><br><br>
<div class="modal fade" id="mySlider" tabindex="-1" role="dialog" aria-labelledby="mySliderLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Tutup</span></button>
<h4 class="modal-title" id="mySliderLabel"><?php echo $title?></h4>
</div>
<div class="modal-body">
<form ACTION="" method = "POST" enctype="multipart/form-data">
<div class="form-group">
<div class="w3-content w3-display-container">
<?php
$sql = "SELECT * FROM storytelling WHERE title = '$title' ORDER BY id";
$result = mysqli_query($db, $sql);
while($row = $result -> fetch_array())
{
?>
<div class="w3-display-container mySlides">
<?php echo "<img src = 'images/".$row['image']."' style='width:100%'>"; ?>
<div class="w3-display-bottomright w3-large w3-container w3-padding-16 w3-black">
<?php echo $row['text']?>
</div>
</div>
<?php
}
?>
<button class="w3-button w3-display-left w3-black" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-display-right w3-black" onclick="plusDivs(1)">❯</button>
<script>
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
<?php if(isset($_POST['save']))
{
//target folder to keep the media
$target = "images/".basename($_FILES['image']['name']);
//get all submitted data from form
$image = $_FILES['image']['name'];
$text = $_POST['text'];
if(!empty($_FILES['image']['name']))
{
$sql = "INSERT INTO storytelling(title, image, text ) VALUES ('$title', '$image', '$text')";
$result=mysqli_query($db, $sql);
if($result){
$message = "Cerita akan ditambah selepas diluluskan admin";
echo "<script type='text/javascript'>alert('$message');</script>";
header("Refresh:0");
} else {
$message = "Cerita gagal ditambah";
echo "<script type='text/javascript'>alert('$message');</script>";
}
move_uploaded_file($_FILES['image']['tmp_name'], $target);
echo "<script type='text/javascript'>location.href='?title=$title';</script>";
}
else
{
$message = "Sila pilih semua fail";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
?>
</div>
</form>
</div>
</div>
</div>
</div>
May I know how to view the next image in the modal without it closing ?
Thank you.
My selector when selected all is updating only 1 row? however if i select a row, it cannot be updated? please see my code if something's wrong, needed help.
This is the form:
<form action="read_message.php" method="post">
<div class="pull-right">
<button class="btn btn-info" name="read"><i class="icon-check"></i> Read</button>
Check All <input type="checkbox" name="selectAll" id="checkAll" />
<script>
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>
</div>
<ul class="nav nav-pills">
<li class="active"><i class="icon-envelope-alt"></i>inbox</li>
<li class=""><i class="icon-envelope-alt"></i>Send messages</li>
</ul>
<?php
$query_announcement = mysql_query("select * from message_received
LEFT JOIN user ON user.user_id = message_received.user_id
where message_received.receiver_id = '$session_id' order by date_sent DESC
")or die(mysql_error());
$count_my_message = mysql_num_rows($query_announcement);
if ($count_my_message != '0'){
while($row = mysql_fetch_array($query_announcement)){
$id = $row['message_id'];
$id_2 = $row['message_id'];
$fn = $row['firstname'];
$ln = $row['lastname'];
$status = $row['message_status'];
$sender = $row['user_id'];
$sender_name = $fn.' '.$ln;
$receiver = $row['receiver_id'];
?><div class="alert alert-info">
<div class="post" id="del<?php echo $id; ?>">
<div class="message_content">
<?php echo $row['content']; ?>
</div>
<div class="pull-right">
<?php if ($status == 'read'){
}else{ ?>
<input id="" class="" name="selector[]" type="checkbox" value="<?php echo $id; ?>">
<?php } ?>
</div>
<hr>
Send by: <strong><?php echo $fn.' '.$ln; ?></strong>
<i class="icon-calendar"></i> <?php echo $row['date_sent']; ?>
<div class="pull-right">
<a class="btn btn-link" href="#reply<?php echo $id; ?>" data-toggle="modal" ><i class="icon-reply"></i> Reply </a>
</div>
<div class="pull-right">
<a class="btn btn-link" href="#<?php echo $id; ?>" data-toggle="modal" ><i class="icon-remove"></i> Remove </a>
<?php include("remove_inbox_message_modal.php"); ?>
<?php include("reply_inbox_message_modal_user.php"); ?>
</div>
</div>
</div>
<?php }}else{ ?>
<div class="alert alert-info"><i class="icon-info-sign"></i> No Message Inbox</div>
<?php } ?>
</form>
However, nevermind the isset for reply, the problem is the first function for isset read, what's wrong with the query? this is the function for the selector, read_message.php,
<?php include('connect.php'); ?>
<?php
include('session.php');
if (isset($_POST['read'])){
$id=$_POST['selector'];
$N = count($id);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("update message_received set message_status = 'read' where message_id='$id[$i]'");
}
echo "<script> alert('Successfully Updated') </script>";
echo " <script>location.replace('messages.php')</script>";
}
?>
<?php
if (isset($_POST['reply'])){
$sender = $_POST['sender'];
$receiver = $_POST['receiver'];
$id2=$_POST['id2'];
$qwe = $_POST['qwe'];
mysql_query("update message_received set message_status = 'read' where message_id='$id2'");
mysql_query("insert into message_received (user_id,receiver_id,content,date_sent) values('$receiver','$sender','$qwe',NOW())")or die(mysql_error());
mysql_query("insert into message_sent (receiver_id,user_id,content,date_sent) values('$sender','$receiver','$qwe',NOW())")or die(mysql_error());
echo "<script> alert('Your message has been sent') </script>";
echo " <script>location.replace('messages.php')</script>";
?>
<script>
alert('Message Sent');
window.location ="messages.php";
</script>
<?php
}
?>
I need slide down multiple-level vertical menu with Headings of sections of the catalog
I use bootstrap btn-group-vertical:
<?php
if($slider_enabled){
?>
<div class='clearfix'></div>
<div class='clearfix'></div>
<div class="col-xs-3">
<div class='index-slider1'>
<div class="btn-group-vertical1 open" role="group" aria-label="Vertical">
<?php
$arrarr1[0] = 0;
$arrarr2 = array();
$categories1 = $categories;
$ccount=0; $ccount1=0; $ccount2=0; $clevel=0;
while($ccount1!=count($categories)) {
$ccount2++;
if(count($categories1[$ccount]["childs"])>0) {
?>
<div class="btn-group-vertical1 open" role="group" aria-label="Vertical">
<button id="btnGroupVerticalDrop_<?=($ccount2.".".$ccount1.".".$clevel.".".$ccount);?>" type="button" class="btn btn-default1 dropdown-toggle dropdown-menu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<?php
$tcnt = -1;
while(++$tcnt<=$clevel) {
echo " ";
}
echo $categories1[$ccount]["name"];
?>
<span class="caret right1"></span>
</button>
<ul class="dropdown-menu1 drop" aria-labelledby="btnGroupVerticalDrop_<?=($ccount2.".".$ccount1.".".$clevel.".".$ccount);?>">
<?php
array_push($arrarr2, array($ccount, $categories1, $strcount));
$categories1 = $categories1[$ccount]["childs"]; $ccount=-1;
$clevel++;
$strcount = substr($strcount, 0, strrpos($strcount, "."));
?>
<?php
} else {
?>
<button type="button" class="btn btn-default1" id="<?=($ccount2.".".$ccount1.".".$clevel.".".$ccount);?>">
<?php
$tcnt = -1;
while(++$tcnt<$clevel) {
echo " ";
}
echo $categories1[$ccount]["name"];
?>
</button>
<?php
}
while($ccount==(count($categories1)-1)) {
$arrarr1 = array_pop($arrarr2);
$strcount = $arrarr1[2]; $categories1 = $arrarr1[1]; $ccount = $arrarr1[0];
$clevel--;
?>
</ul>
</div>
<?php
}
if(count($arrarr2)==0) {
$ccount1++;
}
$ccount++;
}
?>
</div>
</div>
</div>
<div class="col-xs-9"></div>
<?php
}
?>
<script type='text/javascript'>
$(document).ready(function(){
$(".drop").click(function(event){
event.stopPropagation();
});
});
</script>
Issue: First level of menu is slide up and slide down but second level and so on is not response. The purpose is to make slide down catalog of Headings sections which will be as link to the goods page. Maybe there is allready solution of the developed catalog?
I am surprised to see my top login bar cannot show any change after user login.
Other element of in this bar like logo, decorative div show as it but after 'login to change username' & 'registration to change logout' & 'all notification' display like I am not logged in.
I cannot understand where is my wrong. It cannot show any error also.
Please see my code:
Included my every pages:
<?php include_once("top_login.php"); ?>
my top_login.php
<?php include_once("login/session.php"); ?>
<div id="toplogin">
<div class="logintext1">
<?
if($session->logged_in){
echo '<a class="logintext" href=../login/myprocess.php>Logout</a>';
} else {
echo '<a class="logintext" href="../login/regis.php">Register</a>';
}
?>
</div>
<div class="logintext2">
<?
if($session->logged_in){
echo '<a class="logintext" href="../login/mn.php">'.$_SESSION["username"].'</a>';
} else {
echo '<a class="logintext" href="../login/mn.php">Log In</a>';
}
?>
</div>
<div class="logintext3">
<?
if($session->logged_in){
echo '<a class="logintext" href="#"><img style="padding:2px 2px" src="http://www.mywebsite.com/images/nof2.png" /></a>';
} else {
echo '<a class="logintext" href="../login/mn.php"><img style="padding:2px 2px" src="http://www.mywebsite.com/images/nof.png" /> </a>';
}
?>
</div>
</div>
What is the best way to set flash data messages when session have timed out and then be able to get message on login page.
I have a warning variable that would like to use but can not seem to get it working with sessions timed out I have it redirecting to the login page one sessions have timed out.
But not sure best way to set flash data using my error array, any idea's.
Login Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends MX_Controller {
private $error = array();
public function __construct() {
parent::__construct();
$this->load->library('user');
$this->load->library('form_validation');
$this->lang->load('common/login', 'english');
}
public function index() {
$this->form_validation->set_rules('username', 'Username', 'required|min_length[4]|max_length[12]');
$this->form_validation->set_rules('password', 'Password', 'required|xss_clean');
if($this->form_validation->run($this) == false) {
$data['title'] = $this->lang->line('heading_title');
$data['text_heading'] = $this->lang->line('text_heading');
if (array_key_exists('warning', $this->error)) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (null !==($this->session->flashdata('message_name'), $this->error)) {
$data['message'] = $this->session->set_flashdata('message_name', 'This is my message');
} else {
$data['message'] = '';
}
$this->load->view('common/login', $data);
} else{
if($this->validate()) {
redirect('dashboard');
} else {
$data['title'] = $this->lang->line('heading_title');
$data['text_heading'] = $this->lang->line('text_heading');
if (array_key_exists('warning', $this->error)) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (null !==($this->session->flashdata('message_name'), $this->error)) {
$data['message'] = $this->session->set_flashdata('message_name', 'This is my message');
} else {
$data['message'] = '';
}
$this->load->view('common/login', $data);
}
}
}
function validate() {
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($this->user->login($username, $password)) {
return true;
} else {
$this->error['warning'] = $this->lang->line('error_login');
return !$this->error;
}
}
}
Login View
<?php echo modules::run('common/header/index');?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-md-4 col-md-offset-4 col-sm-offset-2 col-sm-8">
<div class="panel panel-default">
<div class="panel-heading"><h2 class="panel-title"><i class="fa fa-key"></i> <?php echo $text_heading; ?></h2></div>
<div class="panel-body">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<?php echo form_open('login');?>
<div class="form-group">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-user"></i> </span>
<input type="text" name="username" value="" placeholder="Username" class="form-control" size="50" />
</div>
<?php echo form_error('username', '<div class="text-danger">', '</div>'); ?>
</div>
<div class="form-group">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" name="password" value="" placeholder="Password" class="form-control"/>
</div>
<?php echo form_error('password', '<div class="text-danger">', '</div>'); ?>
</div>
<div class="form-group">
<div class="text-right">
<button type="submit" class="btn btn-primary"><i class="fa fa-key"></i> Login</button>
</div>
</div>
</form>
</div><!--/. Panel Body -->
</div><!--/. Panel Panel Default -->
</div>
</div>
</div>
<?php echo modules::run('common/footer/index');?>
set_flshdat is codeigniter function that will only be available for next server request and then automatically cleared. you can see in detail here flashdata and search for set_flashdata in this link
so if you need message after redirect to other page or same page
set flashdata on first requested controller page
$this->session->set_flashdata('message_name', 'This is my message');
and on second server request or your redirection page will get this flash data using below
echo $this->session->flashdata('message_name');
So, basically if you don't want to redirect page and want to load view
//set data in controller
$data['message_name'] = 'This is my message'
//and pass this to view
$this->load->view('yourview_name', $data);
And in your view page just write
echo $message_name;