I am using some code to show editor a link to edit specific pages
but it is causing 500 internal server error for users who are not-logged-in
I am a starter and need immediate help
My code is
<?php
global $current_user, $wpdb;
$role = $wpdb->prefix . 'capabilities';
$current_user->role = array_keys($current_user->$role);
$ncaps = count($current_user->role);
$role = $current_user->role[$ncaps - 1];
if ($role == "editor") {
echo '<div class="user-tips">
<h4><u>Edit Equity Market</u></h4>
<h5><button class="btn btn-primary btn-sm">Edit Intraday Tips</button></h5>
<h5><button class="btn btn-primary btn-sm">Edit Positional Tips</button></h5>
<h4><u>Edit Commodity Market</u></h4>
<h5><button class="btn btn-primary btn-sm">Edit Commodity Tips</button></h5>
</div>';
}
else {
echo "";
}
?>
Thanks in advance
Try using function is_user_logged_in():
<?php
if ( is_user_logged_in() && current_user_can('edit_others_pages') ) {
echo '<div class="user-tips">
<h4><u>Edit Equity Market</u></h4>
<h5><button class="btn btn-primary btn-sm">Edit Intraday Tips</button></h5>
<h5><button class="btn btn-primary btn-sm">Edit Positional Tips</button></h5>
<h4><u>Edit Commodity Market</u></h4>
<h5><button class="btn btn-primary btn-sm">Edit Commodity Tips</button></h5>
</div>';
}
?>
EDIT: I also improved the check for roles a little. See Roles and Capabilities for others.
Related
I have a fetch the JSON records from the database I need to link a href tag to the code but unable. Whats wrong with me? In a console, I see simple td without a href tag.
htmlData += '<tr><td><a href="base_url + "'order/getWork/'" + ord_id">'
+ord_item_Json_string[i].code+'</a></td>
<td>'+ord_item_Json_string[i].item+'</td>
<td>'+ord_item_Json_string[i].size+'</td>
<td>'+ord_item_Json_string[i].color+'</td>
<td>'+ord_item_Json_string[i].qty+'</td><td>'+"New Order"+'</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal" id="create-jobcard">Create Card</button></td>
</tr>';
$('#OrdItem tbody').empty();
$('#OrdItem tbody').append(htmlData);
you have a problem with quotations marks( "" / '' ) try this out,
htmlData += '<tr><td><a href="'+base_url+'order/getWork/" + ord_id">'
+ord_item_Json_string[i].code+'</a></td>
<td>'+ord_item_Json_string[i].item+'</td>
<td>'+ord_item_Json_string[i].size+'</td>
<td>'+ord_item_Json_string[i].color+'</td>
<td>'+ord_item_Json_string[i].qty+'</td><td>'+"New Order"+'</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal" id="create-jobcard">Create Card</button></td>
</tr>';
hope this helps
I'm having a problem with my script. The file wont open if the filename has single quote.
Is there a way to prevent single quote in window.open?
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print($contRow['cont_file']); ?>','<?php print($contRow['cont_file']); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
here's the output
7TATTOOED ON MY MIND CHORDS (ver 2) by D'Sound # Ultimate-Guitar
Sample Output 1.
Sample Output 2.
You should encode your filename I think:
urlencode($contRow['cont_file'])
I tried this code:
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print(addslashes($contRow['cont_file'])); ?>','<?php print(addslashes($contRow['cont_file'])); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
and It works like a charm. thanks anyway. Credits to the one who deleted he's post but it works.
I was using ajax calls. when I click on the edit link it would pop up a modal with all the information. I now want to change it, so that it goes to an edit page instead. The part I need changed is the onclick on the edit link bellow in the code from edit_record to instead call a function in my controller called edit. Any help would be appreciated I spent quit a long time trying different ways and keep getting errors.
Here is the controller function code called ajax_list
public function ajax_list()
{
$list = $this->your_table->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $your_table) {
$no++;
$row = array();
$row[] = $your_table->name;
$row[] = $your_table->title;
$row[] = $your_table->body;
//add html for action
$row[] = '<a class="btn btn-sm btn-link " href="javascript:void()" title="Edit" onclick="edit_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm text-warning" href="javascript:void()" title="Hapus" onclick="delete_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->your_table->count_all(),
"recordsFiltered" => $this->your_table->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
Here is the code in my your_controller called edit
//loads a single record with the data dispalyed for editing
function edit($id)
{
$data['r']=$this->your_table->get_by_id($id);
$this->load->view('pages/edit', $data);
}
//updates data in the database from the edit function
function save_edit()
{
$id=$this->input->post('txtid');
$data=array(
'name'=>$this->input->post('txtname'),
'title'=>$this->input->post('txttitle'),
'body'=>$this->input->post('txtbody'));
$this->db->where('id', $id);
$this->db->update('your_table', $data);
redirect('your_controller/index');
}
If your controller is called "edit" and your method has the same name, just change to:
//add html for action
$row[] = '<a class="btn btn-sm btn-link " href="/edit/edit/'.$your->table->id.'" title="Edit"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm text-warning" href="javascript:void()" title="Hapus" onclick="delete_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
This is my Controller:
public function anyData()
{
$myID = Auth::guard('cashier')->user()->id;
$players = User::where('parent_id','=', $myID)
->where('delete', '=', 1)
->orderBy(DB::raw('LENGTH(name),name'))
->get(['id', 'name', 'score', 'alarm', 'bonus_from_percentage']);
return Datatables::of($players)
->addColumn('actions4', function ($players) {
return
'
<a href="#" data-id="'.$players->id.'" data-name="'.$players->name.'" data-target="#actions-modal" class="open-playerID btn btn-warning" data-toggle="modal"
data-target="#actions-modal" data-toggle="tooltip" data-placement="top" title="'.trans('cashier.SETTINGS').'"><span class="glyphicon glyphicon-cog"></span></a>
';
})
->addColumn('actions3', function ($players) {
return
'
<button type="button" class="'.changeClass($players->alarm).'"
value="OK" onclick="Enable('.$players->id.','.$players->alarm.')" id="enable"/><span class="glyphicon glyphicon-ok-circle"></span></button>
';
})
->addColumn('actions2', function ($players) {
return
'
<a href="#" data-toggle="modal" data-id="'.$players->id.'" data-target="#changeplayerpassword-modal" data-toggle="tooltip" data-placement="top" title="'.trans('cashier.CHANGEPLAYERPASS').'" class="playeridchangepass btn btn-warning">
<span class="glyphicon glyphicon-edit"></span></a>
<a href="#" data-id="'.$players->id.'" data-name="'.$players->name.'" data-target="#delete-modal" class="open-delete btn btn-warning" data-toggle="modal"
data-target="#delete-modal" data-toggle="tooltip" data-placement="top" title="'.trans('cashier.DELETE').'" ><span class="glyphicon glyphicon-remove"></span></a>
';
})
->addColumn('actions', function ($players) {
return
'<div class="btn-group text-center">
<button onclick="changeValueIn(this);" class="btn btn-primary btn-sm" style="width: 50px;" data-score-id="' . AppHelper::ToEuroC($players->score) . '" data-player-id="' . $players->id . '" data-name-id="' . $players->name . '" data-toggle="modal" data-target="#In">IN</button>
<button onclick="changeValue(this)"class="btn btn-danger btn-sm" data-score-id="' . AppHelper::ToEuroC($players->score) . '"data-player-id="' . $players->id . '" data-name-id="' . $players->name . '" data-toggle="modal" data-target="#Out">OUT</button>
</div>
';
})
->addColumn('score', function ($players) {
return AppHelper::ToEuroC($players->score);
})
->addColumn('bonus_from_percentage', function ($players) {
return AppHelper::ToEuroC($players->bonus_from_percentage);
})
->addColumn('players', function ($players) {
return ($players->name) . ' ' .dikOn($players->id);
})
->make(true);
}
This script i run to refresh table each 5 seconds:
// REFRESH TABLE
function refreshptable() {
if (table != null)
table.ajax.reload(null, false);
setTimeout(refreshplayers
, 5000);
}
wen i upload on server my laravel project (i have active around 300 Users online)
CPU load going 200+
On my old PHP code (No Laravel) CPU load is 10-15
its something wrong with datatables or is laravel ?
i check the request is same no loops and all querys is same the only difference is laravel..
on TOP -C laravel use 3% my old code use 0.3% ..
I want to make my one column with if else condition when data table render.
I am using laravel 4.2
my current code is
$result = DB::table('flowers')
->select('flowers.id as id', 'flowers.name as name',
'flowers.price as price',
'flowers.description as description','flowers.quality as quality',
'flowers.picture as picture','flowers.visibility_status as visibility_status');
return Datatables::of($result)
->edit_column('visibility_status', '<button type="button" onclick="activeFunction({{ $id }})" class="btn btn-primary bpad">Make Featured</button>')
->edit_column('picture', '<img src="{{ $picture }}" alt="flower Image" height="150">')
->add_column('edit', '<i class="icon-list-alt"></i>Edit')
->add_column('delete', '<i class="icon-trash"></i>Delete')
->make();
i want visibility_status column implement with if else condition like
if($visibility_status==1)
{
<div id="active454">
<button type="button" onclick="activeFunction(454)" class="btn btn-primary bpad">Make Featured</button></div>
<div id="block454" style="display:none"><button type="button" onclick="blockFunction(454)" class="btn btn-danger bpad">Make Unfeatured</button></div>
}
else
{
<div id="active454" style="display:none">
<button type="button" onclick="activeFunction(454)" class="btn btn-primary bpad">Make Featured</button></div>
<div id="block454" ><button type="button" onclick="blockFunction(454)" class="btn btn-danger bpad">Make Unfeatured</button></div>
}
Is it possible
I am not familiar with laravel but will risk it.
CSS
.hide{display:none;}
PHP Init
$class1 = array('class="hide" ','');
$class2 = array('','class="hide" ');
In PHP HTML generation
<div id="active454" $class1[$visibility_status]>
<div id="block454" $class2[$visibility_status]>
If $visibility_status is ambiguous as far as data type or null use:
$classX[intval($visibility_status)]