function create($stationName, $desc) { $this->set('name', $stationName); $this->set('description', $desc); parent::create(); //return $this->id; }
function create($name) { global $nodeId; #$name = sotf_Utils::magicQuotes(/*$nodeId . '_' . */ $name); #$count = $this->db->getOne("SELECT count(*) FROM sotf_contacts WHERE name = '$name'"); #if($count > 0) # return ERROR_NAME_USED; $this->data['name'] = $name; return parent::create(); }
function create($name) { global $config; $id = $this->findByNameLocal($name); if ($id) { debug("Create contact", "Failed, name in use"); return false; } $this->data['name'] = $name; return parent::create(); }
$smarty->assign("ROLE_SELECTED", $roleSelected); } else { $smarty->assign("ROLE_SELECTED", $role->get('role_id')); } } if ($save) { if (!$roleSelected) { raiseError("No role selected!"); } // save if (is_object($role)) { $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->update(); } else { if (sotf_ComplexNodeObject::findRole($objectId, $contactId, $roleSelected)) { // this role already exists $page->addStatusMsg("role_exists"); $page->redirectSelf(); } $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $objectId); $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->create(); } $page->redirect("closeAndRefresh.php?anchor=roles"); } // general data $obj =& $repository->getObject($objectId); $smarty->assign("OBJECT_ID", $objectId);
/** static: create contact record from metadata */ function importContact($contactData, $contactRole, $prgId, $stationId, $admins) { global $db, $permissions, $repository, $vocabularies, $config; $db->begin(); // find out what should go into the 'name' field if ($contactData['type'] == 'organisation') { $name = $contactData['organizationname']; } elseif ($contactData['type'] == 'individual') { $name = $contactData['firstname'] . ' ' . $contactData['lastname']; } else { logError("unknown type of contact: " . $contactData['type']); return null; } // if not exists, create new contact $id = sotf_Contact::findByNameLocal($name); if (!$id) { $contact = new sotf_Contact(); $status = $contact->create($name, $stationId); if (!$status) { //$page->addStatusMsg('contact_create_failed'); return null; } // add permissions for all station admins (??) while (list(, $adminId) = each($admins)) { $permissions->addPermission($contact->id, $adminId, 'admin'); } } else { $contact = $repository->getObject($id); } //debug("contactData", $contactData); // set/update contact data $contact->set('acronym', $contactData['organizationacronym']); $contact->set('alias', $contactData['alias']); $contact->set('url', $contactData['uri']); $contact->set('email', $contactData['email']); $contact->set('address', $contactData['address']); $contact->update(); // determine role if ($contactData['role']) { $language = 'eng'; // for now $rid = $vocabularies->getRoleId($contactData['role'], $language); if ($rid) { $contactRole = $rid; } } // create role if (!sotf_ComplexNodeObject::findRole($prgId, $contact->id, $contactRole)) { $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $prgId); $role->set('contact_id', $contact->id); $role->set('role_id', $contactRole); $role->create(); } $db->commit(); // fetch logo from url and store if (!empty($contactData['logo'])) { $url = $contactData['logo']; if ($handle = @fopen($url, 'rb')) { $contents = ""; while (!feof($handle)) { $contents .= fread($handle, 8192); } /* do { $data = fread ($handle, 100000); if (strlen($data) == 0) { break; } //debug("received", strlen($data)); $contents .= $data; } while(0); */ fclose($handle); $tmpFile = tempnam($config['tmpDir'], 'logo_u'); debug("received logo from", $url); sotf_Utils::save($tmpFile, $contents); chmod($tmpFile, 0660); $contact->setIcon($tmpFile); unlink($tmpFile); } else { logError("Could not fetch icon from {$url}"); } } return $contact->id; }
/** * Sets logo of the station * * @param object $file sotf_File object represents the logo * @return boolean True if the function succeeded, else false * @use $db * @use $config['iconWidth'] * @use $config['iconHeight'] */ function setIcon($file) { if (parent::setIcon($file)) { $iconFile = $this->getStationDir() . '/icon.png'; sotf_Utils::save($iconFile, $this->getIcon()); return true; } else { return false; } }