$prj['item_state'] = 2;
        $r_url = empty($ritem['item_alias']) ? cot_url('projects', 'c=' . $ritem['item_cat'] . '&id=' . $id, '', true) : cot_url('projects', 'c=' . $ritem['item_cat'] . '&al=' . $ritem['item_alias'], '', true);
        if (!$usr['isadmin']) {
            $rbody = cot_rc($L['project_senttovalidation_mail_body'], array('user_name' => $item['user_name'], 'prj_name' => $item['item_title'], 'sitename' => $cfg['maintitle'], 'link' => COT_ABSOLUTE_URL . $r_url));
            cot_mail($item['user_email'], $L['project_senttovalidation_mail_subj'], $rbody);
        }
    } else {
        $prj['item_state'] = 0;
        $r_url = empty($item['item_alias']) ? cot_url('projects', 'c=' . $item['item_cat'] . '&id=' . $id, '', true) : cot_url('projects', 'c=' . $item['item_cat'] . '&al=' . $item['item_alias'], '', true);
        if (!$usr['isadmin']) {
            $rbody = cot_rc($L['project_added_mail_body'], array('user_name' => $item['user_name'], 'prj_name' => $item['item_title'], 'sitename' => $cfg['maintitle'], 'link' => COT_ABSOLUTE_URL . cot_url('projects', 'id=' . $id, '', true)));
            cot_mail($item['user_email'], $L['project_added_mail_subj'], $rbody);
        }
    }
    $db->update($db_projects, $prj, "item_id=" . (int) $id);
    cot_projects_sync($item['item_cat']);
    /* === Hook === */
    foreach (cot_getextplugins('projects.preview.save.done') as $pl) {
        include $pl;
    }
    /* ===== */
    cot_redirect($r_url);
    exit;
}
$out['subtitle'] = $L['projects'];
$mskin = cot_tplfile(array('projects', 'preview', $structure['projects'][$item['item_cat']]['tpl']));
/* === Hook === */
foreach (cot_getextplugins('projects.preview.main') as $pl) {
    include $pl;
}
/* ===== */
/**
 * Updates a project in the CMS.
 * @param  integer $id    Project ID
 * @param  array   $ritem Project data
 * @param  array   $auth  Permissions array
 * @return boolean        TRUE on success, FALSE on error
 */
function cot_projects_update($id, &$ritem, $auth = array())
{
    global $cache, $cfg, $db, $db_projects, $db_structure, $structure, $L;
    if (cot_error_found()) {
        return false;
    }
    if (count($auth) == 0) {
        $auth = cot_projects_auth($ritem['item_cat']);
    }
    if (!empty($ritem['item_alias'])) {
        $prj_count = $db->query("SELECT COUNT(*) FROM {$db_projects} WHERE item_alias = ? AND item_id != ?", array($ritem['item_alias'], $id))->fetchColumn();
        if ($prj_count > 0) {
            $ritem['item_alias'] = $ritem['item_alias'] . rand(1000, 9999);
        }
    }
    $item = $db->query("SELECT * FROM {$db_projects} WHERE item_id = ?", $id)->fetch();
    if (!$cfg['projects']['preview']) {
        $ritem['item_state'] = !$cfg['projects']['prevalidate'] || $auth['isadmin'] ? 0 : 2;
    } else {
        $ritem['item_state'] = 1;
    }
    if (!$db->update($db_projects, $ritem, 'item_id = ?', $id)) {
        return false;
    }
    cot_projects_sync($item['item_cat']);
    cot_projects_sync($ritem['item_cat']);
    cot_extrafield_movefiles();
    /* === Hook === */
    foreach (cot_getextplugins('projects.edit.update.done') as $pl) {
        include $pl;
    }
    /* ===== */
    return true;
}