function photos_access_update_access in Album Photos 7.3
Same name and namespace in other branches
- 8.5 photos_access/photos_access.module \photos_access_update_access()
- 8.4 photos_access/photos_access.module \photos_access_update_access()
- 6.0.x photos_access/photos_access.module \photos_access_update_access()
Update access to album.
2 calls to photos_access_update_access()
- photos_access_node_insert in photos_access/
photos_access.module - Implements hook_node_insert().
- photos_access_node_update in photos_access/
photos_access.module - Implements hook_node_update().
File
- photos_access/
photos_access.module, line 216
Code
function photos_access_update_access($node) {
if (variable_get('photos_access_' . $node->type, 0)) {
if (!$node->privacy['eid']) {
if ($node->privacy['updateuser']) {
// Check if row already exists for this node.
$acc['updateid'] = db_query("SELECT id FROM {photos_access_album} WHERE nid = :nid", array(
':nid' => $node->nid,
))
->fetchField();
$node->privacy['vid'] = $node->privacy['eid'] = $acc['updateid'];
if ($acc['updateid']) {
// Update existing record.
db_update('photos_access_album')
->fields(array(
'viewid' => isset($node->privacy['viewid']) ? $node->privacy['viewid'] : 0,
))
->condition('id', $acc['updateid'])
->execute();
}
else {
$acc['updateid'] = db_insert('photos_access_album')
->fields(array(
'nid' => $node->nid,
'viewid' => $node->privacy['viewid'],
))
->execute();
}
_photos_access_usersave($node->privacy['updateuser'], $acc['updateid']);
}
}
else {
$remove = FALSE;
if (isset($node->privacy['updateremove']) && !empty($node->privacy['updateremove'])) {
$remove = _photos_access_usersdel($node->privacy['updateremove'], $node->privacy['eid']);
}
if (isset($node->privacy['updateuser']) && !empty($node->privacy['updateuser'])) {
_photos_access_usersave($node->privacy['updateuser'], $node->privacy['eid']);
}
$acc['updateid'] = $node->privacy['eid'];
}
if (!$node->privacy['vid']) {
// Double check for existing photos_access_album record.
$node->privacy['vid'] = $node->privacy['eid'] = db_query("SELECT id FROM {photos_access_album} WHERE nid = :nid", array(
':nid' => $node->nid,
))
->fetchField();
}
if (!$node->privacy['vid']) {
$acc['viewid'] = db_insert('photos_access_album')
->fields(array(
'nid' => $node->nid,
'viewid' => isset($node->privacy['viewid']) ? $node->privacy['viewid'] : 0,
'pass' => isset($node->privacy['pass']) && !empty($node->privacy['pass']) ? md5($node->privacy['pass']) : 0,
))
->execute();
if ($node->privacy['viewid'] && $node->privacy['viewuser']) {
_photos_access_usersave($node->privacy['viewuser'], $acc['viewid'], FALSE);
}
}
else {
switch ($node->privacy['viewid']) {
case 0:
case 1:
db_query('UPDATE {photos_access_album} SET viewid = :viewid WHERE id = :id', array(
':viewid' => $node->privacy['viewid'],
':id' => $node->privacy['vid'],
));
_photos_access_usersdel(0, $node->privacy['vid'], 1);
break;
case 2:
db_query('UPDATE {photos_access_album} SET viewid = :viewid WHERE id = :id', array(
':viewid' => $node->privacy['viewid'],
':id' => $node->privacy['vid'],
));
if ($node->privacy['viewuser']) {
_photos_access_usersave($node->privacy['viewuser'], $node->privacy['vid'], FALSE);
}
if (isset($node->privacy['viewremove'])) {
_photos_access_usersdel($node->privacy['viewremove'], $node->privacy['vid']);
}
break;
case 3:
$old = isset($_SESSION['photos_access_' . $node->nid]) ? $_SESSION['photos_access_' . $node->nid] : array();
$old_pass = isset($old['pass']) ? $old['pass'] : '';
$pass = isset($node->privacy['pass']) && !empty($node->privacy['pass']) ? md5($node->privacy['pass']) : $old_pass;
db_query("UPDATE {photos_access_album} SET viewid = :viewid, pass = :pass WHERE id = :id", array(
':viewid' => $node->privacy['viewid'],
':pass' => $pass,
':id' => $node->privacy['vid'],
));
_photos_access_usersdel(0, $node->privacy['vid'], 1);
}
$acc['viewid'] = $node->privacy['viewid'];
$acc['vid'] = $node->privacy['vid'];
}
$_SESSION['photos_access_ac_' . $node->nid] = $acc;
unset($_SESSION['photos_access_' . $node->nid]);
}
}