Authorized delete process to logged in user.

12 views
Skip to first unread message

Jacqueline Tito

unread,
Apr 17, 2012, 10:36:15 PM4/17/12
to Croogo
I have this function in my controller,

public function process() {

$action = $this->request->data['Ticket']['action'];
$ids = array();
foreach ($this->request->data['Ticket'] AS $id => $value) {
if ($id != 'action' && $value['id'] == 1) {
$ids[] = $id;
}
}
if (count($ids) == 0 || $action == null) {
$this->Session->setFlash(__('No items selected.'), 'default',
array('class' => 'error'));
$this->redirect(array('action' => 'index'));
}
if ($action == 'delete' &&
$this->Ticket->deleteAll(array('Ticket.id' => $ids), true,
true)) {
$this->Session->setFlash(__('Ticket successfully deleted.'),
'default', array('class' => 'success'));
} else {
$this->Session->setFlash(__('An error occurred.'), 'default',
array('class' => 'error'));
}
$this->redirect(array('action' => 'index'));
}
and in the index.ctp

<?php foreach ($tickets as $ticket): ?>

<tr class="alternate-row">
<td><?php echo $this->Form-
>checkbox('Ticket.' . $ticket['Ticket']['id'] . '.id'); ?></td>
<td><?php echo
$ticket['Ticket']['id']; ?></td>
<td><?php echo
$ticket['Ticket']['title']; ?></td>
<td><?php echo
$ticket['Ticket']['description']; ?></td>
<td><?php echo
$ticket['Ticket']['requestor_name']; ?></td>
<td><?php echo
$ticket['Ticket']['email']; ?></td>
<td><?php echo
$ticket['Ticket']['phone']; ?></td>
<td><?php echo
$ticket['Ticket']['status']; ?></td>
<td><?php echo
$ticket['Ticket']['remarks']; ?></td>
<td>
<?php echo $this->Html-
>link('', '/ticket/ticket/edit/' . $ticket['Ticket']['id'],
array('class' => 'icon-1 info-tooltip')); ?>
<?php
echo $this->Form-
>postLink('', array(
'action' => 'delete',
$ticket['Ticket']['id']), array(
'class' => 'icon-2
info-tooltip',
'confirm' => 'Are you
sure you want to delete?'));
?>
</td>
</tr>
<?php endforeach; ?>

.... Function process allows multiple delete through the selected
checkboxes in my index.ctp..

Now, my problem is, how to authorized multiple delete into the current
logged in user.

Sample:
I am the logged in user. I can only delete multiple selected items
which I have posted.
Is that possible? Hope for immediate response.

Jacqueline Tito

unread,
Apr 17, 2012, 10:36:50 PM4/17/12
to Croogo
Reply all
Reply to author
Forward
0 new messages