You are here

function mobile_tools_roles_edit_mobile_role in Mobile Tools 6.3

Function helping in saving and deleting the mobile roles

Parameters

$op: the operation that has to be performed: 'delete' will delete the mobile role, 'add' will add the mobile role.

$rid: Role id of the related desktop role

$mrid: Role id of the mobile role (only when deleting)

1 call to mobile_tools_roles_edit_mobile_role()
mobile_tools_roles_configuration_form_submit in ./mobile_tools_roles.admin.inc
Submit function for the mobile tools / mobile roles configuration page

File

./mobile_tools_roles.module, line 111
Contains the functionality to add mobile user roles

Code

function mobile_tools_roles_edit_mobile_role($op, $rid, $mrid = '') {
  switch ($op) {
    case 'delete':
      db_query("DELETE FROM {role} WHERE rid = %d", $mrid);
      db_query("DELETE FROM {mobile_tools_roles_relations} WHERE mrid = %d", $mrid);
      db_query("DELETE FROM {permission} WHERE rid = %d", $mrid);
      break;
    case 'add':
      $query = "SELECT name FROM {role} WHERE rid = %d";
      $name = db_result(db_query($query, $rid));
      $result = db_query("INSERT INTO {role} (name) VALUES ('%s')", $name . ' (Mobile)');
      $mrid = db_last_insert_id('role', 'rid');
      db_query("INSERT INTO {mobile_tools_roles_relations} (rid, mrid) VALUES (%d, %d)", $rid, $mrid);
      $perm = db_fetch_object(db_query("SELECT * FROM {permission} WHERE rid = %d", $rid));
      if (!empty($perm)) {
        db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", $mrid, $perm->perm, $perm->tid);
      }
      break;
  }
}