function save($id, $vars, &$errors) { global $cfg; if ($id && $id != $vars['id']) { $errors['err'] = __('Missing or invalid Dept ID (internal error).'); } if (!$vars['name']) { $errors['name'] = __('Name required'); } elseif (strlen($vars['name']) < 4) { $errors['name'] = __('Name is too short.'); } elseif (($did = Dept::getIdByName($vars['name'])) && $did != $id) { $errors['name'] = __('Department already exists'); } if (!$vars['ispublic'] && $cfg && $vars['id'] == $cfg->getDefaultDeptId()) { $errors['ispublic'] = __('System default department cannot be private'); } if ($errors) { return false; } $sql = 'SET updated=NOW() ' . ' ,ispublic=' . db_input(isset($vars['ispublic']) ? $vars['ispublic'] : 0) . ' ,email_id=' . db_input(isset($vars['email_id']) ? $vars['email_id'] : 0) . ' ,tpl_id=' . db_input(isset($vars['tpl_id']) ? $vars['tpl_id'] : 0) . ' ,sla_id=' . db_input(isset($vars['sla_id']) ? $vars['sla_id'] : 0) . ' ,autoresp_email_id=' . db_input(isset($vars['autoresp_email_id']) ? $vars['autoresp_email_id'] : 0) . ' ,manager_id=' . db_input($vars['manager_id'] ? $vars['manager_id'] : 0) . ' ,dept_name=' . db_input(Format::striptags($vars['name'])) . ' ,dept_signature=' . db_input(Format::sanitize($vars['signature'])) . ' ,group_membership=' . db_input($vars['group_membership']) . ' ,ticket_auto_response=' . db_input(isset($vars['ticket_auto_response']) ? $vars['ticket_auto_response'] : 1) . ' ,message_auto_response=' . db_input(isset($vars['message_auto_response']) ? $vars['message_auto_response'] : 1); if ($id) { $sql = 'UPDATE ' . DEPT_TABLE . ' ' . $sql . ' WHERE dept_id=' . db_input($id); if (db_query($sql) && db_affected_rows()) { return true; } $errors['err'] = sprintf(__('Unable to update %s.'), __('this department')) . ' ' . __('Internal error occurred'); } else { if (isset($vars['id'])) { $sql .= ', dept_id=' . db_input($vars['id']); } $sql = 'INSERT INTO ' . DEPT_TABLE . ' ' . $sql . ',created=NOW()'; if (db_query($sql) && ($id = db_insert_id())) { return $id; } $errors['err'] = sprintf(__('Unable to create %s.'), __('this department')) . ' ' . __('Internal error occurred'); } return false; }
function save($id, $vars, &$errors) { global $cfg; if ($id && $id != $vars['id']) { $errors['err'] = 'Missing or invalid Dept ID (internal error).'; } if (!$vars['email_id'] || !is_numeric($vars['email_id'])) { $errors['email_id'] = 'Email selection required'; } if (!is_numeric($vars['tpl_id'])) { $errors['tpl_id'] = 'Template selection required'; } if (!$vars['name']) { $errors['name'] = 'Name required'; } elseif (strlen($vars['name']) < 4) { $errors['name'] = 'Name is too short.'; } elseif (($did = Dept::getIdByName($vars['name'])) && $did != $id) { $errors['name'] = 'Department already exist'; } if (!$vars['ispublic'] && $vars['id'] == $cfg->getDefaultDeptId()) { $errors['ispublic'] = 'System default department can not be private'; } if ($errors) { return false; } $sql = 'SET updated=NOW() ' . ' ,ispublic=' . db_input($vars['ispublic']) . ' ,email_id=' . db_input($vars['email_id']) . ' ,tpl_id=' . db_input($vars['tpl_id']) . ' ,sla_id=' . db_input($vars['sla_id']) . ' ,autoresp_email_id=' . db_input($vars['autoresp_email_id']) . ' ,manager_id=' . db_input($vars['manager_id'] ? $vars['manager_id'] : 0) . ' ,dept_name=' . db_input(Format::striptags($vars['name'])) . ' ,dept_signature=' . db_input(Format::striptags($vars['signature'])) . ' ,ticket_auto_response=' . db_input(isset($vars['ticket_auto_response']) ? $vars['ticket_auto_response'] : 1) . ' ,message_auto_response=' . db_input(isset($vars['message_auto_response']) ? $vars['message_auto_response'] : 1); if ($id) { $sql = 'UPDATE ' . DEPT_TABLE . ' ' . $sql . ' WHERE dept_id=' . db_input($id); if (db_query($sql) && db_affected_rows()) { return true; } $errors['err'] = 'Unable to update ' . Format::htmlchars($vars['name']) . ' Dept. Error occurred'; } else { $sql = 'INSERT INTO ' . DEPT_TABLE . ' ' . $sql . ',created=NOW()'; if (db_query($sql) && ($id = db_insert_id())) { return $id; } $errors['err'] = 'Unable to create department. Internal error'; } return false; }