Exemplo n.º 1
0
 function AddList()
 {
     global $user;
     $return = array();
     if ($user) {
         require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
         $title = isset($_REQUEST['title']) ? urldecode($_REQUEST['title']) : '';
         if (strlen(trim($title)) == 0) {
             $return['result'] = "false";
             $return['message'] = "You must provide a title for the list";
         } else {
             $list = new UserList();
             $list->title = $title;
             $list->user_id = $user->id;
             //Check to see if there is already a list with this id
             $existingList = false;
             if ($list->find(true)) {
                 $existingList = true;
             }
             $list->description = urldecode($_REQUEST['desc']);
             $list->public = $_REQUEST['public'];
             if ($existingList) {
                 $list->update();
             } else {
                 $list->insert();
             }
             if (isset($_REQUEST['recordId'])) {
                 $recordToAdd = urldecode($_REQUEST['recordId']);
                 require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
                 //Check to see if the user has already added the title to the list.
                 $userListEntry = new UserListEntry();
                 $userListEntry->listId = $list->id;
                 $userListEntry->groupedWorkPermanentId = $recordToAdd;
                 if (!$userListEntry->find(true)) {
                     $userListEntry->dateAdded = time();
                     $userListEntry->insert();
                 }
             }
             $return['result'] = 'true';
             $return['newId'] = $list->id;
             if ($existingList) {
                 $return['message'] = "Updated list {$title} successfully";
             } else {
                 $return['message'] = "Created list {$title} successfully";
             }
         }
     } else {
         $return['result'] = "false";
         $return['message'] = "You must be logged in to create a list";
     }
     return $return;
 }