本文整理汇总了PHP中Company::setClientOfId方法的典型用法代码示例。如果您正苦于以下问题:PHP Company::setClientOfId方法的具体用法?PHP Company::setClientOfId怎么用?PHP Company::setClientOfId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Company
的用法示例。
在下文中一共展示了Company::setClientOfId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: die
/**
* Finish the installation - create owner company and administrator
*
* @param void
* @return null
*/
function complete_installation()
{
if (Companies::getOwnerCompany() instanceof Company) {
die('Owner company already exists');
// Somebody is trying to access this method even if the user already exists
}
// if
$this->setLayout('complete_install');
$form_data = array_var($_POST, 'form');
tpl_assign('form_data', $form_data);
if (array_var($form_data, 'submitted') == 'submitted') {
try {
$admin_password = trim(array_var($form_data, 'admin_password'));
$admin_password_a = trim(array_var($form_data, 'admin_password_a'));
if (trim($admin_password) == '') {
throw new Error(lang('password value required'));
}
// if
if ($admin_password != $admin_password_a) {
throw new Error(lang('passwords dont match'));
}
// if
DB::beginWork();
Users::delete();
// clear users table
Companies::delete();
// clear companies table
// Create the administrator user
$administrator = new User();
$administrator->setId(1);
$administrator->setUsername(array_var($form_data, 'admin_username'));
$administrator->setEmail(array_var($form_data, 'admin_email'));
$administrator->setPassword($admin_password);
$administrator->setIsAdmin(true);
$administrator->setAutoAssign(true);
$administrator->save();
// Create the contact for administrator
$administrator_contact = new Contact();
$administrator_contact->setId(1);
$administrator_contact->setCompanyId(1);
$administrator_contact->setEmail(array_var($form_data, 'admin_email'));
$administrator_contact->setUserId($administrator->getId());
$administrator_contact->setDisplayName($administrator->getUsername());
$administrator_contact->save();
// Create a company
$company = new Company();
$company->setId(1);
$company->setClientOfId(0);
$company->setName(array_var($form_data, 'company_name'));
$company->setCreatedById(1);
$company->save();
DB::commit();
$this->redirectTo('access', 'login');
} catch (Exception $e) {
tpl_assign('error', $e);
DB::rollback();
}
// try
}
// if
}
示例2: add
/**
* Add contact
*
* @access public
* @param void
* @return null
*/
function add()
{
$this->setTemplate('add_contact');
$company_id = get_id('company_id', null, 0);
$company = Companies::findById($company_id);
if (!Contact::canAdd(logged_user(), $company)) {
flash_error(lang('no access permissions'));
$this->redirectToReferer(get_url('dashboard', 'index'));
}
// if
$contact = new Contact();
$im_types = ImTypes::findAll(array('order' => '`id`'));
$contact_data = array_var($_POST, 'contact');
if (!is_array($contact_data)) {
$contact_data = array('company_id' => $company_id);
// array
}
// if
$user_data = array_var($contact_data, 'user');
if (!is_array($user_data)) {
$user_data = array('password_generator' => 'random');
// array
}
// if
tpl_assign('contact', $contact);
tpl_assign('company', $company);
tpl_assign('contact_data', $contact_data);
tpl_assign('user_data', $user_data);
tpl_assign('im_types', $im_types);
$avatar = array_var($_FILES, 'new_avatar');
if (is_array($avatar) && isset($avatar['size']) && $avatar['size'] != 0) {
try {
if (!isset($avatar['name']) || !isset($avatar['type']) || !isset($avatar['size']) || !isset($avatar['tmp_name']) || !is_readable($avatar['tmp_name'])) {
throw new InvalidUploadError($avatar, lang('error upload file'));
}
// if
$valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
$max_width = config_option('max_avatar_width', 50);
$max_height = config_option('max_avatar_height', 50);
if ($avatar['size']) {
if (!in_array($avatar['type'], $valid_types) || !($image = getimagesize($avatar['tmp_name']))) {
throw new InvalidUploadError($avatar, lang('invalid upload type', 'JPG, GIF, PNG'));
} elseif (!$contact->setAvatar($avatar['tmp_name'], $max_width, $max_height, false)) {
throw new Error($avatar, lang('error edit avatar'));
$contact->setAvatarFile('');
}
// if
}
// if
} catch (Exception $e) {
flash_error($e->getMessage());
}
} else {
$contact->setAvatarFile('');
}
// if
if (is_array(array_var($_POST, 'contact'))) {
$contact->setFromAttributes($contact_data);
try {
// Company info
if ($_POST['contact']['company']['what'] == 'existing') {
$company_id = $_POST['contact']['company_id'];
} else {
$company = new Company();
$company->setName($_POST['contact']['company']['name']);
$company->setTimezone($_POST['contact']['company']['timezone']);
$company->setClientOfId(owner_company()->getId());
$company->save();
$company_id = $company->getId();
}
// if
$contact->setCompanyId($company_id);
$contact->setUserId(0);
$contact->save();
if (plugin_active('tags')) {
$contact->setTagsFromCSV(array_var($contact_data, 'tags'));
}
$contact->clearImValues();
foreach ($im_types as $im_type) {
$value = trim(array_var($contact_data, 'im_' . $im_type->getId()));
if ($value != '') {
$contact_im_value = new ContactImValue();
$contact_im_value->setContactId($contact->getId());
$contact_im_value->setImTypeId($im_type->getId());
$contact_im_value->setValue($value);
$contact_im_value->setIsDefault(array_var($contact_data, 'default_im') == $im_type->getId());
$contact_im_value->save();
}
// if
}
// foreach
ApplicationLogs::createLog($contact, null, ApplicationLogs::ACTION_ADD);
DB::commit();
//.........这里部分代码省略.........
示例3: unset
function import_from_vcard()
{
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
@set_time_limit(0);
ini_set('auto_detect_line_endings', '1');
if (isset($_GET['from_menu']) && $_GET['from_menu'] == 1) {
unset($_SESSION['go_back']);
}
if (isset($_SESSION['go_back'])) {
unset($_SESSION['go_back']);
ajx_current("start");
}
tpl_assign('import_type', 'contact');
if (!Contact::canAdd(logged_user(), active_or_personal_project())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
// if
$this->setTemplate('vcard_import');
$filedata = array_var($_FILES, 'vcard_file');
if (is_array($filedata) && !array_var($_GET, 'step2')) {
$filename = ROOT . '/tmp/' . logged_user()->getId() . 'temp.vcf';
copy($filedata['tmp_name'], $filename);
//ajx_current("empty");
} else {
if (array_var($_GET, 'step2')) {
$filename = ROOT . '/tmp/' . logged_user()->getId() . 'temp.vcf';
$result = $this->read_vcard_file($filename);
unlink($filename);
$import_result = array('import_ok' => array(), 'import_fail' => array());
foreach ($result as $contact_data) {
try {
DB::beginWork();
if (isset($contact_data['photo_tmp_filename'])) {
$file_id = FileRepository::addFile($contact_data['photo_tmp_filename'], array('public' => true));
$contact_data['picture_file'] = $file_id;
unlink($contact_data['photo_tmp_filename']);
unset($contact_data['photo_tmp_filename']);
}
if (isset($contact_data['company_name'])) {
$company = Companies::findOne(array("conditions" => "`name` = '" . mysql_real_escape_string($contact_data['company_name']) . "'"));
if ($company == null) {
$company = new Company();
$company->setName($contact_data['company_name']);
$company->setClientOfId(logged_user()->getCompanyId());
$company->save();
ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_ADD);
}
$contact_data['company_id'] = $company->getId();
unset($contact_data['company_name']);
}
$contact_data['import_status'] = '(' . lang('updated') . ')';
$fname = mysql_real_escape_string(array_var($contact_data, "firstname"));
$lname = mysql_real_escape_string(array_var($contact_data, "lastname"));
$contact = Contacts::findOne(array("conditions" => "firstname = '" . $fname . "' AND lastname = '" . $lname . "' OR email <> '' AND email = '" . array_var($contact_data, "email") . "'"));
$log_action = ApplicationLogs::ACTION_EDIT;
if (!$contact) {
$contact = new Contact();
$contact_data['import_status'] = '(' . lang('new') . ')';
$log_action = ApplicationLogs::ACTION_ADD;
$can_import = active_project() != null ? $contact->canAdd(logged_user(), active_project()) : can_manage_contacts(logged_user());
} else {
$can_import = $contact->canEdit(logged_user());
}
if ($can_import) {
$contact->setFromAttributes($contact_data);
$contact->save();
ApplicationLogs::createLog($contact, null, $log_action);
$contact->setTagsFromCSV(array_var($_GET, 'tags'));
if (active_project() instanceof Project) {
$pc = ProjectContacts::findOne(array("conditions" => "contact_id = " . $contact->getId() . " AND project_id = " . active_project()->getId()));
if (!$pc) {
$pc = new ProjectContact();
$pc->setContactId($contact->getId());
$pc->setProjectId(active_project()->getId());
$pc->setRole(array_var($contact_data, 'role'));
$pc->save();
}
$contact->addToWorkspace(active_project());
}
$import_result['import_ok'][] = array('firstname' => $fname, 'lastname' => $lname, 'email' => $contact_data['email'], 'import_status' => $contact_data['import_status']);
} else {
throw new Exception(lang('no access permissions'));
}
DB::commit();
} catch (Exception $e) {
DB::rollback();
$fail_msg = substr_utf($e->getMessage(), strpos_utf($e->getMessage(), "\r\n"));
$import_result['import_fail'][] = array('firstname' => $fname, 'lastname' => $lname, 'email' => $contact_data['email'], 'import_status' => $contact_data['import_status'], 'fail_message' => $fail_msg);
}
}
$_SESSION['go_back'] = true;
tpl_assign('import_result', $import_result);
}
}
//.........这里部分代码省略.........
示例4: array
//.........这里部分代码省略.........
if (!isset($avatar['name']) || !isset($avatar['type']) || !isset($avatar['size']) || !isset($avatar['tmp_name']) || !is_readable($avatar['tmp_name'])) {
throw new InvalidUploadError($avatar, lang('error upload file'));
}
// if
$valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
$max_width = config_option('max_avatar_width', 50);
$max_height = config_option('max_avatar_height', 50);
if ($avatar['size']) {
if (!in_array($avatar['type'], $valid_types) || !($image = getimagesize($avatar['tmp_name']))) {
throw new InvalidUploadError($avatar, lang('invalid upload type', 'JPG, GIF, PNG'));
} elseif (!$contact->setAvatar($avatar['tmp_name'], $max_width, $max_height, false)) {
throw new Error($avatar, lang('error edit avatar'));
$contact->setAvatarFile('');
}
// if
}
// if
} catch (Exception $e) {
flash_error($e->getMessage());
}
} else {
$contact->setAvatarFile('');
}
// if
try {
DB::beginWork();
$contact->setFromAttributes($new_contact_data);
if (array_var($company_data, 'what') == 'existing') {
$company_id = $new_contact_data['company_id'];
} else {
$company = new Company();
$company->setName(array_var($company_data, 'name'));
$company->setTimezone(array_var($company_data, 'timezone'));
$company->setClientOfId(owner_company()->getId());
$company->save();
$company_id = $company->getId();
}
// if
$contact->setCompanyId($company_id);
// User account info
if (array_var($user_data, 'add_account') == "yes") {
$user = new User();
$user->setFromAttributes($user_data);
if (array_var($user_data, 'password_generator') == 'random') {
// Generate random password
$password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13);
} else {
// Validate user input
$password = array_var($user_data, 'password');
if (trim($password) == '') {
throw new Error(lang('password value required'));
}
// if
if ($password != array_var($user_data, 'password_a')) {
throw new Error(lang('passwords dont match'));
}
// if
}
// if
$user->setPassword($password);
$user->save();
$contact->setUserId($user->getId());
} else {
$contact->setUserId(0);
}
// if
示例5: die
/**
* Finish the installation - create owner company and administrator
*
* @param void
* @return null
*/
function complete_installation()
{
if (Companies::getOwnerCompany() instanceof Company) {
die('Owner company already exists');
// Somebody is trying to access this method even if the user already exists
}
// if
$form_data = array_var($_POST, 'form');
tpl_assign('form_data', $form_data);
if (array_var($form_data, 'submited') == 'submited') {
try {
$admin_password = trim(array_var($form_data, 'admin_password'));
$admin_password_a = trim(array_var($form_data, 'admin_password_a'));
if (trim($admin_password) == '') {
throw new Error(lang('password value required'));
}
// if
if ($admin_password != $admin_password_a) {
throw new Error(lang('passwords dont match'));
}
// if
DB::beginWork();
Users::delete();
// clear users table
Companies::delete();
// clear companies table
// Create the administrator user
$administrator = new User();
$administrator->setId(1);
$administrator->setCompanyId(1);
$administrator->setUsername(array_var($form_data, 'admin_username'));
$administrator->setEmail(array_var($form_data, 'admin_email'));
$administrator->setPassword($admin_password);
$administrator->setCanEditCompanyData(true);
$administrator->setCanManageConfiguration(true);
$administrator->setCanManageSecurity(true);
$administrator->setCanManageWorkspaces(true);
$administrator->setCanManageContacts(true);
$administrator->setCanManageTemplates(true);
$administrator->setCanManageReports(true);
$administrator->setCanManageTime(true);
$administrator->setCanAddMailAccounts(true);
$administrator->setAutoAssign(false);
$administrator->setPersonalProjectId(1);
$administrator->setType('admin');
$administrator->save();
$group = new Group();
$group->setName('administrators');
$group->setAllPermissions(true);
$group->setId(Group::CONST_ADMIN_GROUP_ID);
$group->save();
$group_user = new GroupUser();
$group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID);
$group_user->setUserId($administrator->getId());
$group_user->save();
$project = new Project();
$project->setId(1);
$project->setP1(1);
$project->setName(new_personal_project_name($administrator->getUsername()));
$project->setDescription(lang('files'));
$project->setCreatedById($administrator->getId());
$project->save();
$project_user = new ProjectUser();
$project_user->setProjectId($project->getId());
$project_user->setUserId($administrator->getId());
$project_user->setCreatedById($administrator->getId());
$project_user->setAllPermissions(true);
$project_user->save();
// Create a company
$company = new Company();
$company->setId(1);
$company->setClientOfId(0);
$company->setName(array_var($form_data, 'company_name'));
$company->setCreatedById(1);
$company->save();
DB::commit();
$this->redirectTo('access', 'login');
} catch (Exception $e) {
tpl_assign('error', $e);
DB::rollback();
}
// try
}
// if
}