Skip to content

Commit

Permalink
Changes: Implemented multiple inbox master
Browse files Browse the repository at this point in the history
  • Loading branch information
back2arie committed Apr 4, 2012
1 parent bf07d35 commit 537bfbe
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 21 deletions.
2 changes: 1 addition & 1 deletion application/config/kalkun_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
| Must be valid user ID
|
*/
$config['inbox_owner_id'] = '1';
$config['inbox_owner_id'] = array('1', '2', '3');

/*
|--------------------------------------------------------------------------
Expand Down
42 changes: 25 additions & 17 deletions application/models/kalkun_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,32 @@ function get_sms_used($option, $param, $type = 'out')
*/
function add_sms_used($user_id, $type = 'out')
{
$date = date("Y-m-d");
$count = $this->_check_sms_used($date, $user_id,$type);
$this->db->where('sms_date', $date);
$this->db->where('id_user', $user_id);

if($this->db->count_all_results('sms_used')>0)
{
$this->db->set($type.'_sms_count', $count+1);
$this->db->where('sms_date', $date);
$this->db->where('id_user', $user_id);
$this->db->update('sms_used');
}
else
if (!is_array($user_id))
{
$user_id[] = $user_id;
}

foreach($user_id as $uid)
{
$this->db->set($type.'_sms_count', '1');
$this->db->set('sms_date', $date);
$this->db->set('id_user', $user_id);
$this->db->insert('sms_used');
$date = date("Y-m-d");
$count = $this->_check_sms_used($date, $uid, $type);
$this->db->where('sms_date', $date);
$this->db->where('id_user', $uid);

if($this->db->count_all_results('sms_used')>0)
{
$this->db->set($type.'_sms_count', $count+1);
$this->db->where('sms_date', $date);
$this->db->where('id_user', $uid);
$this->db->update('sms_used');
}
else
{
$this->db->set($type.'_sms_count', '1');
$this->db->set('sms_date', $date);
$this->db->set('id_user', $uid);
$this->db->insert('sms_used');
}
}
}

Expand Down
59 changes: 57 additions & 2 deletions application/models/message_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,63 @@ function update_processed($id)
// Update ownership
function update_owner($msg_id, $user_id)
{
$data = array ('id_user' => $user_id, 'id_inbox' => $msg_id);
$this->db->insert('user_inbox', $data);
if (!is_array($user_id))
{
$user_id[] = $user_id;
}

$count = count($user_id);
for ($i=0; $i<$count; $i++)
{
$this->db->where('id_user', $user_id[$i]);
$this->db->where('id_inbox', $msg_id);
$exist = $this->db->count_all_results('user_inbox');
if ($exist == 0)
{
$data = array ('id_user' => $user_id[$i], 'id_inbox' => $msg_id);
$this->db->insert('user_inbox', $data);
}

// not the last element
if ($i != $count-1)
{
$data = $this->db->get_where('inbox', array('ID' => $msg_id));
$data = $data->row();
unset($data->ID);
$data->Processed = 'true';
if (!empty($data->UDH))
{
// Generate new UDH
$newUDH = '';
for ($j=1; $j<=4; $j++)
{
$newUDH .= strtoupper(dechex(mt_rand(0, 255)));
}
$data->UDH = $newUDH.substr($data->UDH, -4);
}
$this->db->insert('inbox', $data);
$new_msg_id = $this->db->insert_id();

// check multipart
$multipart = array('type' => 'inbox', 'option' => 'check', 'id_message' => $msg_id);
$tmp_check = $this->get_multipart($multipart);

if ($tmp_check->row('UDH')!='')
{
$multipart = array('option' => 'all', 'udh' => substr($tmp_check->row('UDH'),0,8));
$multipart['phone_number'] = $tmp_check->row('SenderNumber');
$multipart['type'] = 'inbox';
foreach($this->get_multipart($multipart)->result() as $part)
{
unset($part->ID);
$part->Processed = 'true';
$part->UDH = $newUDH.substr($part->UDH, -4);
$this->db->insert('inbox', $part);
}
}
$msg_id = $new_msg_id;
}
}
}

//Save Canned Response
Expand Down
2 changes: 1 addition & 1 deletion application/views/main/users/users_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="left_column">
<div id="pbkname">
<input type="checkbox" class="select_user" />&nbsp;<span style="font-weight: bold;"><?php echo $tmp->realname;?></span>
<?php if($this->config->item('inbox_owner_id')==$tmp->id_user) echo "<sup>( Inbox Master )</sup>"; ?>
<?php if(in_array($tmp->id_user, $this->config->item('inbox_owner_id'))) echo "<sup>( Inbox Master )</sup>"; ?>
</div>
</div>
<div class="right_column">
Expand Down

0 comments on commit 537bfbe

Please sign in to comment.