Changeset 2429 for trunk/include


Ignore:
Timestamp:
Jul 12, 2008, 2:30:27 AM (16 years ago)
Author:
rvelices
Message:
  • add to caddie on picture page done through ajax
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r2413 r2429  
    281281}
    282282
     283function ws_caddie_add($params, &$service)
     284{
     285  if (!is_admin())
     286  {
     287    return new PwgError(401, 'Access denied');
     288  }
     289  if ( empty($params['image_id']) )
     290  {
     291    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
     292  }
     293  global $user;
     294  $query = '
     295SELECT id
     296  FROM '.IMAGES_TABLE.' LEFT JOIN '.CADDIE_TABLE.' ON id=element_id AND user_id='.$user['id'].'
     297  WHERE id IN ('.implode(',',$params['image_id']).')
     298    AND element_id IS NULL';
     299  $datas = array();
     300  foreach ( array_from_query($query, 'id') as $id )
     301  {
     302    array_push($datas, array('element_id'=>$id, 'user_id'=>$user['id']) );
     303  }
     304  if (count($datas))
     305  {
     306    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     307    mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
     308  }
     309  return count($datas);
     310}
    283311
    284312/**
Note: See TracChangeset for help on using the changeset viewer.