Ejemplo n.º 1
0
 public function expunge($messages = false)
 {
     $items = new Dase_DBO_Item($this->db);
     $items->collection_id = $this->id;
     foreach ($items->find() as $item) {
         Dase_Log::info(LOG_FILE, "item {$this->ascii_id}:{$item->serial_number} deleted");
         if ($messages) {
             print "item {$this->ascii_id}:{$item->serial_number} deleted\n";
         }
         $item->expunge();
     }
     $item_types = new Dase_DBO_ItemType($this->db);
     $item_types->collection_id = $this->id;
     foreach ($item_types->find() as $type) {
         $type->expunge();
     }
     $atts = new Dase_DBO_Attribute($this->db);
     $atts->collection_id = $this->id;
     foreach ($atts->find() as $a) {
         $a->delete();
     }
     $cms = new Dase_DBO_CollectionManager($this->db);
     $cms->collection_ascii_id = $this->ascii_id;
     foreach ($cms->find() as $cm) {
         $cm->delete();
     }
     $this->delete();
     Dase_Log::info(LOG_FILE, "{$this->ascii_id} deleted");
     if ($messages) {
         print "{$this->ascii_id} collection deleted\n";
     }
 }
Ejemplo n.º 2
0
 public static function listAsAtom($db, $app_root)
 {
     $cm = new Dase_DBO_CollectionManager($db);
     $cms = $cm->find();
     $feed = new Dase_Atom_Feed();
     $feed->setTitle('DASe Collection Managers');
     $feed->setId($app_root . '/admin/managers');
     //fix to be latest update
     $feed->setUpdated(date(DATE_ATOM));
     $feed->addAuthor();
     $feed->addLink($app_root . '/admin/managers.atom', 'self');
     $feed->addCategory($app_root, "http://daseproject.org/category/base_url");
     foreach ($cms as $manager) {
         $entry = $feed->addEntry();
         $manager->injectAtomEntryData($entry, $app_root);
     }
     return $feed->asXml();
 }
Ejemplo n.º 3
0
 public function getManagerJson($r)
 {
     $coll = $r->get('collection_ascii_id');
     $eid = $r->get('eid');
     $cm = Dase_DBO_CollectionManager::get($this->db, $coll, $eid);
     $result = array();
     if ($cm) {
         $result['eid'] = $eid;
         $result['collection_ascii_id'] = $coll;
         $result['auth_level'] = $cm->auth_level;
         $r->renderResponse(Dase_Json::get($result));
     } else {
         $r->renderError(404);
     }
 }
Ejemplo n.º 4
0
 public function postToCreateSample($r)
 {
     $resp = array();
     $url = "http://daseproject.org/collection/sample.atom";
     $feed = Dase_Atom_Feed::retrieve($url);
     $coll_ascii_id = $feed->getAsciiId();
     $feed->ingest($r, true);
     $cm = new Dase_DBO_CollectionManager($this->db);
     $cm->dase_user_eid = $u->eid;
     $cm->collection_ascii_id = $coll_ascii_id;
     $cm->auth_level = 'superuser';
     $cm->created = date(DATE_ATOM);
     $cm->insert();
     $login_url = APP_ROOT . '/login/form';
 }
Ejemplo n.º 5
0
 public function postToManagers($r)
 {
     if (!$r->has('auth_level')) {
         $params['msg'] = 'You must select an Authorization Level';
         $r->renderRedirect('manage/' . $this->collection->ascii_id . '/managers', $params);
     }
     if (!$r->has('dase_user_eid')) {
         $params['msg'] = 'You must enter an EID';
         $r->renderRedirect('manage/' . $this->collection->ascii_id . '/managers', $params);
     }
     $eid = strtolower($r->get('dase_user_eid'));
     if (!Dase_DBO_DaseUser::get($this->db, $eid)) {
         $params['msg'] = 'User ' . $eid . ' does not yet exist';
         $r->renderRedirect('manage/' . $this->collection->ascii_id . '/managers', $params);
     }
     $mgr = new Dase_DBO_CollectionManager($this->db);
     $mgr->dase_user_eid = $eid;
     $mgr->auth_level = $r->get('auth_level');
     $mgr->collection_ascii_id = $this->collection->ascii_id;
     $mgr->created = date(DATE_ATOM);
     $mgr->created_by_eid = $this->user->eid;
     try {
         $mgr->insert();
         $params['msg'] = 'success!';
     } catch (Exception $e) {
         $params['msg'] = 'there was a problem:' . $e->getMessage();
     }
     $r->renderRedirect('manage/' . $this->collection->ascii_id . '/managers', $params);
 }
Ejemplo n.º 6
0
 public function getManagerEmail($r)
 {
     $cms = new Dase_DBO_CollectionManager($this->db);
     foreach ($cms->find() as $cm) {
         if ('none' != $cm->auth_level) {
             $person = Utlookup::getRecord($cm->dase_user_eid);
             if (isset($person['email'])) {
                 $managers[] = $person['name'] . " <" . $person['email'] . ">";
             }
         }
     }
     $r->response_mime_type = 'text/plain';
     $r->renderResponse(join("\n", array_unique($managers)));
 }
Ejemplo n.º 7
0
$update = false;
foreach ($users->find() as $user) {
    $user->updated = date(DATE_ATOM, strtotime($user->updated));
    $user->created = date(DATE_ATOM, strtotime($user->created));
    if ($user->eid != strtolower($user->eid)) {
        $user->eid = strtolower($user->eid);
    }
    if (!$user->has_access_exception) {
        $user->has_access_exception = 0;
    }
    print "updating user {$user->eid}\n";
    if ($update) {
        $user->update();
    }
}
$cms = new Dase_DBO_CollectionManager();
foreach ($cms->find() as $cm) {
    if ($cm->dase_user_eid != strtolower($cm->dase_user_eid)) {
        print "updating manager {$cm->dase_user_eid}\n";
        $cm->dase_user_eid = strtolower($cm->dase_user_eid);
        if ($update) {
            $cm->update();
        }
    }
}
$items = new Dase_DBO_Item();
foreach ($items->find() as $item) {
    if ($item->created_by_eid != strtolower($item->created_by_eid)) {
        print "updating item {$item->created_by_eid}\n";
        $item->created_by_eid = strtolower($item->created_by_eid);
        if ($update) {
Ejemplo n.º 8
0
 function create($db, $r)
 {
     $atom_author = $this->getAuthorName();
     $user = $r->getUser('http');
     $collection_name = $this->getTitle();
     if (!$collection_name) {
         $r->renderError(400, 'no title');
     }
     $c = new Dase_DBO_Collection($db);
     $c->collection_name = $collection_name;
     if ($r->has('ascii_id')) {
         $ascii_id = $r->get('ascii_id');
         //set in handler based on Slug
     } else {
         $ascii_id = $this->getAsciiId();
     }
     if (!$ascii_id) {
         $ascii_id = $c->createAscii();
     }
     if (Dase_DBO_Collection::get($db, $ascii_id) || $c->findOne()) {
         $r->renderError(409, 'collection already exists');
     }
     $c->ascii_id = $ascii_id;
     $coll_media_dir = MEDIA_DIR . '/' . $ascii_id;
     if (file_exists($coll_media_dir)) {
         //todo: think about this...
         //$r->renderError(409,'collection media archive exists');
     }
     $c->is_public = 0;
     $c->created = date(DATE_ATOM);
     $c->updated = date(DATE_ATOM);
     $content = $this->getContent();
     if ($content) {
         $c->description = $content;
     }
     $summary = $this->getSummary();
     if ($summary) {
         $c->admin_notes = $summary;
     }
     if ($c->insert()) {
         $cache = $r->getCache();
         $cache->expire('app_data');
         Dase_Log::info(LOG_FILE, 'created collection ' . $c->collection_name);
         if (mkdir("{$coll_media_dir}")) {
             chmod("{$coll_media_dir}", 0775);
             foreach (Dase_Media::$sizes as $size => $access_level) {
                 mkdir("{$coll_media_dir}/{$size}");
                 Dase_Log::info(LOG_FILE, 'created directory ' . $coll_media_dir . '/' . $size);
                 chmod("{$coll_media_dir}/{$size}", 0775);
             }
             symlink($coll_media_dir, $coll_media_dir . '_collection');
         }
         foreach (array('title', 'description', 'keyword', 'rights') as $att) {
             $a = new Dase_DBO_Attribute($db);
             $a->ascii_id = $att;
             $a->attribute_name = ucfirst($att);
             $a->collection_id = $c->id;
             $a->in_basic_search = true;
             $a->is_on_list_display = true;
             $a->is_public = true;
             $a->html_input_type = 'text';
             if ('description' == $att) {
                 $a->html_input_type = 'textarea';
             }
             $a->updated = date(DATE_ATOM);
             if ($a->insert()) {
                 Dase_Log::debug(LOG_FILE, 'created att ' . $att);
             } else {
                 Dase_Log::debug(LOG_FILE, 'problem creating ' . $att);
             }
         }
         $cm = new Dase_DBO_CollectionManager($db);
         $cm->collection_ascii_id = $ascii_id;
         $cm->dase_user_eid = $user->eid;
         $cm->auth_level = 'admin';
         $cm->created = date(DATE_ATOM);
         $cm->created_by_eid = $user->eid;
         if ($cm->insert()) {
             Dase_Log::info(LOG_FILE, 'created admin user ' . $ascii_id . '::' . $user->eid);
         } else {
             Dase_Log::info(LOG_FILE, 'could not create admin user');
         }
         return $ascii_id;
     } else {
         return false;
     }
 }
Ejemplo n.º 9
0
 function checkCollectionAuth($collection, $auth_level)
 {
     if (!$collection) {
         Dase_Log::debug(LOG_FILE, 'attempting get to authorization for non-existing collection');
         return false;
     }
     if ('read' == $auth_level) {
         if ($collection->is_public || 'user' == $collection->visibility || 'public' == $collection->visibility) {
             return true;
         }
     }
     /** this seems wrong (too permissive!)
     		if ('write' == $auth_level) {
     			if (
     				'user' == $collection->visibility || 
     				'public' == $collection->visibility
     			) {
     				return true;
     			}
     		}
     		 */
     $cm = new Dase_DBO_CollectionManager($this->db);
     $cm->collection_ascii_id = $collection->ascii_id;
     //todo: need to account for case here!
     //needs to be case-insensitive
     $cm->dase_user_eid = $this->eid;
     $cm->findOne();
     if ($cm->auth_level) {
         if ('read' == $auth_level) {
             return true;
         } elseif ('write' == $auth_level && in_array($cm->auth_level, array('write', 'admin', 'manager', 'superuser'))) {
             return true;
         } elseif ('admin' == $auth_level && in_array($cm->auth_level, array('admin', 'manager', 'superuser'))) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }