function imagepicker_multitask_groups_form_submit in Image Picker 6.2
Same name and namespace in other branches
- 7 imagepicker.functions.inc \imagepicker_multitask_groups_form_submit()
Submit form
1 string reference to 'imagepicker_multitask_groups_form_submit'
File
- ./
imagepicker.functions.inc, line 726 - Imagepicker functions
Code
function imagepicker_multitask_groups_form_submit($form, &$form_state) {
$simg_ids = $form_state['values']['simg_ids'];
$img_ids = explode('-', $simg_ids);
$returnpath = $form_state['values']['returnpath'];
$action = $form_state['values']['action'];
// list of selected groups
$grouplist = array_filter($form_state['values']['grouplist']);
$gids = '';
foreach ($grouplist as $gid) {
$gids[] = $gid;
}
if (is_array($gids) && count($img_ids)) {
foreach ($img_ids as $img_id) {
foreach ($gids as $gid) {
$sql = "SELECT count(gid) AS ct FROM {imagepicker_group_images} WHERE gid = %d AND img_id = %d";
$result = db_query($sql, array(
$gid,
$img_id,
));
$row = db_fetch_array($result);
$found = FALSE;
if ($row['ct'] > 0) {
$found = TRUE;
}
if ($action == 'add') {
if (!$found) {
// add $img_id to $gid
$rec['gid'] = $gid;
$rec['img_id'] = $img_id;
imagepicker_insert_group_image($rec);
}
}
else {
if ($found) {
// remove $img_id from $gid
imagepicker_delete_group_image($img_id);
}
}
}
}
drupal_set_message(t('%c ', array(
'%c' => format_plural(count($img_ids), '1 image', '@count images'),
)) . ' ' . ($action == 'add' ? t('added') : t('removed')));
}
$rpath = imagepicker_multitask_returnpath($returnpath);
drupal_goto($rpath);
}