function process() { if ($this->validate()) { $this->election_details->name = trim($this->data['txtName']); $this->election_details->vote_date = DB_DataObject_Cast::date($this->data['txtDate']); if ($this->data['chkEnabled']) { $this->election_details->enabled = 1; } else { $this->election_details->enabled = 0; } $this->process_removed_categories(); $this->process_selected_categories(); $this->process_removed_parties(); $this->process_selected_parties(); if ($this->election_details->update() !== false) { $this->load(); // Reload so we get the date back as a string $this->bind(); $this->render(); } else { trigger_error("Unable to save election"); } } else { $this->bind(); $this->render(); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $AddIP, $userid, $group_ids, $AccessOption, $ComplaintsStateOption; $apf_refundment = DB_DataObject::factory('ApfRefundment'); if ($edit_submit) { $apf_refundment->get($apf_refundment->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_refundment->setCategory(stripslashes(trim($_POST['category']))); $apf_refundment->setCompany(stripslashes(trim($_POST['company']))); $apf_refundment->setRefundmenter(stripslashes(trim($_POST['refundmenter']))); $apf_refundment->setReasons(stripslashes(trim($_POST['reasons']))); $apf_refundment->setReply(stripslashes(trim($_POST['reply']))); $apf_refundment->setHandleman(stripslashes(trim($_POST['handleman']))); $apf_refundment->setHandledate(stripslashes(trim($_POST['handledate']))); $apf_refundment->setState(stripslashes(trim($_POST['state']))); $apf_refundment->setAccess(stripslashes(trim($_POST['access']))); $apf_refundment->setActive(stripslashes(trim($_POST['active']))); $apf_refundment->setAddIp($AddIP); $apf_refundment->setGroupid($group_ids); $apf_refundment->setUserid($userid); $val = $apf_refundment->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_refundment->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_refundment->update(); $log_string = $i18n->_("Update") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("refundment/apf_refundment/update/" . $_POST['ID'] . "/ok"); } else { $apf_refundment->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_refundment->insert(); $log_string = $i18n->_("Create") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['create_date']}"; logFileString($log_string); $this->forward("refundment/apf_refundment/"); } } else { $template->setFile(array("MAIN" => "apf_refundment_edit.html")); $template->setBlock("MAIN", "edit_block"); $category_arr = $this->getCategory(); array_shift($AccessOption); array_shift($ComplaintsStateOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "CATEGORYOPTION" => selectTag("category", $category_arr, $_POST['category']), "ACCESSOPTION" => radioTag("access", $AccessOption, $_POST['access']), "STATE_OPTION" => radioTag("state", $ComplaintsStateOption, $_POST['state']), "HANDLE_DATE" => inputDateTag("handledate", $_POST['handledate']), "REASONS_TEXT" => textareaTag('reasons', $_POST['reasons'], false, "ROWS=\"8\" COLS=\"40\""), "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "CATEGORY" => $_POST['category'], "COMPANY" => $_POST['company'], "REFUNDMENTER" => $_POST['refundmenter'], "REASONS" => $_POST['reasons'], "REPLY" => $_POST['reply'], "HANDLEMAN" => $_POST['handleman'], "HANDLEDATE" => $_POST['handledate'], "STATE" => $_POST['state'], "GROUPID" => $_POST['groupid'], "USERID" => $_POST['userid'], "ACCESS" => $_POST['access'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $AddIP, $userid, $group_ids, $AccessOption; $apf_agreement = DB_DataObject::factory('ApfAgreement'); if ($edit_submit) { $apf_agreement->get($apf_agreement->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_agreement->setNoid(stripslashes(trim($_POST['noid']))); $apf_agreement->setCategory(stripslashes(trim($_POST['category']))); $apf_agreement->setEffectdate(stripslashes(trim($_POST['effectdate']))); $apf_agreement->setExpireddate(stripslashes(trim($_POST['expireddate']))); $apf_agreement->setBuyer(stripslashes(trim($_POST['buyer']))); $apf_agreement->setVender(stripslashes(trim($_POST['vender']))); $apf_agreement->setBuyersignature(stripslashes(trim($_POST['buyersignature']))); $apf_agreement->setVendersignature(stripslashes(trim($_POST['vendersignature']))); $apf_agreement->setDescription(stripslashes(trim($_POST['description']))); $apf_agreement->setAccess(stripslashes(trim($_POST['access']))); $apf_agreement->setActive(stripslashes(trim($_POST['active']))); $apf_agreement->setAddIp($AddIP); $apf_agreement->setGroupid($group_ids); $apf_agreement->setUserid($userid); $val = $apf_agreement->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_agreement->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_agreement->update(); $log_string = $i18n->_("Update") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("agreement/apf_agreement/update/" . $_POST['ID'] . "/ok"); } else { $apf_agreement->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_agreement->insert(); $log_string = $i18n->_("Create") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['create_date']}"; logFileString($log_string); $this->forward("agreement/apf_agreement/"); } } else { $template->setFile(array("MAIN" => "apf_agreement_edit.html")); $template->setBlock("MAIN", "edit_block"); $category_arr = $this->getCategory(); array_shift($AccessOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "CATEGORYOPTION" => selectTag("category", $category_arr, $_POST['category']), "EFFECT_DATE" => inputDateTag("effectdate", $_POST['effectdate']), "EXPIRED_DATE" => inputDateTag("expireddate", $_POST['expireddate']), "ACCESSOPTION" => radioTag("access", $AccessOption, $_POST['access']), "DESCRIPTION_TEXT" => textareaTag('description', $_POST['description'], false, "ROWS=\"8\" COLS=\"40\""), "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "NOID" => $_POST['noid'], "CATEGORY" => $_POST['category'], "EFFECTDATE" => $_POST['effectdate'], "EXPIREDDATE" => $_POST['expireddate'], "BUYER" => $_POST['buyer'], "VENDER" => $_POST['vender'], "BUYERSIGNATURE" => $_POST['buyersignature'], "VENDERSIGNATURE" => $_POST['vendersignature'], "DESCRIPTION" => $_POST['description'], "GROUPID" => $_POST['groupid'], "USERID" => $_POST['userid'], "ACCESS" => $_POST['access'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
/** * Register a user with a username on a given provider * @param User User object * @param string username on the given provider * @param provider_name string name of the provider * @return mixed User_username instance if the registration succeeded, false if it did not */ static function register($user, $username, $provider_name) { $user_username = new User_username(); $user_username->user_id = $user->id; $user_username->provider_name = $provider_name; $user_username->username = $username; $user_username->created = DB_DataObject_Cast::dateTime(); if ($user_username->insert()) { return $user_username; } else { return false; } }
function oid_link_user($id, $canonical, $display) { $oid = new User_openid(); $oid->user_id = $id; $oid->canonical = $canonical; $oid->display = $display; $oid->created = DB_DataObject_Cast::dateTime(); if (!$oid->insert()) { $err = PEAR::getStaticProperty('DB_DataObject', 'lastError'); return false; } return true; }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption, $StateOption, $AddIP, $userid, $group_ids; $apf_opportunity = DB_DataObject::factory('ApfOpportunity'); if ($edit_submit) { $apf_opportunity->get($apf_opportunity->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_opportunity->setTitle(stripslashes(trim($_POST['title']))); $apf_opportunity->setAddrees(stripslashes(trim($_POST['addrees']))); $apf_opportunity->setPhone(stripslashes(trim($_POST['phone']))); $apf_opportunity->setFax(stripslashes(trim($_POST['fax']))); $apf_opportunity->setEmail(stripslashes(trim($_POST['email']))); $apf_opportunity->setHomepage(stripslashes(trim($_POST['homepage']))); $apf_opportunity->setLinkMan(stripslashes(trim($_POST['link_man']))); $apf_opportunity->setMemo(stripslashes(trim($_POST['memo']))); $apf_opportunity->setState(stripslashes(trim($_POST['state']))); $apf_opportunity->setActive(stripslashes(trim($_POST['active']))); $apf_opportunity->setAddIp($AddIP); $apf_opportunity->setGroupid($group_ids); $apf_opportunity->setUserid($userid); $val = $apf_opportunity->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_opportunity->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_opportunity->update(); $log_string = $i18n->_("Update") . $i18n->_("Opportunity") . "\t{$_POST['title']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("opportunity/apf_opportunity/update/" . $_POST['ID'] . "/ok"); } else { $apf_opportunity->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_opportunity->insert(); $log_string = $i18n->_("Create") . $i18n->_("Opportunity") . "\t{$_POST['title']}"; logFileString($log_string); $this->forward("opportunity/apf_opportunity/"); } } else { $template->setFile(array("MAIN" => "apf_opportunity_edit.html")); $template->setBlock("MAIN", "edit_block"); array_shift($ActiveOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "STATE_OPTION" => radioTag("state", $StateOption, $_POST['state']), "MEMO_TEXT" => textareaTag("memo", $_POST['memo'], false, "ROWS=\"15\" COLS=\"60\" "), "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "TITLE" => $_POST['title'], "ADDREES" => $_POST['addrees'], "PHONE" => $_POST['phone'], "FAX" => $_POST['fax'], "EMAIL" => $_POST['email'], "HOMEPAGE" => $_POST['homepage'], "LINK_MAN" => $_POST['link_man'], "MEMO" => $_POST['memo'], "STATE" => $_POST['state'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption, $DebitOption, $AddIP, $userid, $group_ids; $apf_finance = DB_DataObject::factory('ApfFinance'); if ($edit_submit) { $apf_finance->get($apf_finance->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_finance->setCategory(stripslashes(trim($_POST['category']))); $apf_finance->setCreateDate(stripslashes(trim($_POST['create_date']))); $apf_finance->setAmount(stripslashes(trim($_POST['amount']))); $apf_finance->setDebit(stripslashes(trim($_POST['debit']))); $apf_finance->setMoney(stripslashes(trim($_POST['money']))); $apf_finance->setMemo(stripslashes(trim($_POST['memo']))); $apf_finance->setActive(stripslashes(trim($_POST['active']))); $apf_finance->setAddIp($AddIP); $apf_finance->setGroupid($group_ids); $apf_finance->setUserid($userid); $val = $apf_finance->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_finance->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_finance->update(); $log_string = $i18n->_("Update") . $i18n->_("Finance") . "\t{$_POST['money']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("finance/apf_finance/update/" . $_POST['ID'] . "/ok"); } else { $apf_finance->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_finance->insert(); $log_string = $i18n->_("Create") . $i18n->_("Finance") . "\t{$_POST['money']}=>{$_POST['create_date']}"; logFileString($log_string); $this->forward("finance/apf_finance/"); } } else { $template->setFile(array("MAIN" => "apf_finance_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['ID'], "CATEGORY" => $_POST['category'], "CREATE_DATE" => $_POST['create_date'], "AMOUNT" => $_POST['amount'], "DEBIT" => $_POST['debit'], "MONEY" => $_POST['money'], "MEMO" => $_POST['memo'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); $category_arr = $this->getCategory(); array_shift($ActiveOption); array_shift($DebitOption); $template->setVar(array("CATEGORYOPTION" => selectTag("category", $category_arr, $_POST['category']), "CREATEDATE" => inputDateTag("create_date", $_POST['create_date']), "AMOUNTTEXT" => textTag("amount", $_POST['amount']), "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "DEBITOPTION" => radioTag("debit", $DebitOption, $_POST['debit']))); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption, $AddIP, $userid, $group_ids; $apf_news = DB_DataObject::factory('ApfNews'); if ($edit_submit) { $apf_news->get($apf_news->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_news->setCategoryId(stripslashes(trim($_POST['category_id']))); $apf_news->setTitle(stripslashes(trim($_POST['title']))); $apf_news->setContent(stripslashes(trim($_POST['content']))); $apf_news->setActive(stripslashes(trim($_POST['active']))); $apf_finance->setAddIp($AddIP); $apf_finance->setGroupid($group_ids); $apf_finance->setUserid($userid); $val = $apf_news->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_news->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_news->update(); $log_string = $i18n->_("Update") . $i18n->_("News") . "\t{$_POST['title']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("news/apf_news/update/" . $_POST['ID'] . "/ok"); } else { $apf_news->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_news->insert(); $log_string = $i18n->_("Create") . $i18n->_("News") . "\t{$_POST['title']}"; logFileString($log_string); $this->forward("news/apf_news/"); } } else { $template->setFile(array("MAIN" => "apf_news_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); $category_arr = $this->getCategory(); array_shift($ActiveOption); $template->setVar(array("ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "CATEGORYOPTION" => selectTag("category_id", $category_arr, $_POST['category_id']))); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "CATEGORY_ID" => $_POST['category_id'], "TITLE" => $_POST['title'], "CONTENT" => $_POST['content'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption; $apf_news_category = DB_DataObject::factory('ApfNewsCategory'); if ($edit_submit) { $apf_news_category->get($apf_news_category->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_news_category->setCategoryName(stripslashes(trim($_POST['category_name']))); $apf_news_category->setOrderid(stripslashes(trim($_POST['orderid']))); $apf_news_category->setActive(stripslashes(trim($_POST['active']))); $apf_news_category->setAddIp(stripslashes(trim($_POST['add_ip']))); $apf_news_category->setCreatedAt(stripslashes(trim($_POST['created_at']))); $apf_news_category->setUpdateAt(stripslashes(trim($_POST['update_at']))); $val = $apf_news_category->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_news_category->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_news_category->update(); $log_string = $i18n->_("Update") . $i18n->_("NewsCategory") . "\t{$_POST['category_name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("news/apf_news_category/update/" . $_POST['ID'] . "/ok"); } else { $apf_news_category->setCreatedAt(DB_DataObject_Cast::dateTime()); $insert_id = $apf_news_category->insert(); $log_string = $i18n->_("Create") . $i18n->_("NewsCategory") . "\t{$_POST['category_name']}"; logFileString($log_string); $apf_news_category->get($insert_id); $apf_news_category->setOrderid($insert_id); $apf_news_category->update(); $this->forward("news/apf_news_category/"); } } else { $template->setFile(array("MAIN" => "apf_news_category_edit.html")); $template->setBlock("MAIN", "edit_block"); array_shift($ActiveOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['ID'], "CATEGORY_NAME" => $_POST['category_name'], "ORDERID" => $_POST['orderid'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function doEditProductPrice() { global $CurrencyFormat; require_once 'I18N/Currency.php'; $args = func_get_args(); $price = $args[0]; $product_id = $args[1]; $company_id = $args[2]; $apf_product_price = DB_DataObject::factory('ApfProductPrice'); $apf_product_price->setCompanyId($company_id); $apf_product_price->setProductId($product_id); $apf_product_price->setPrice($price); $apf_product_price->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_product_price->insert(); $currency = new I18N_Currency($CurrencyFormat); return "<div ondblclick=\"editPrice('" . $product_id . "','" . $company_id . "','" . $price . "')\" >" . $currency->format($price) . "</div>"; }
function process() { if ($this->validate()) { $election = factory::create('election'); $election->name = trim($this->data['txtName']); $election->vote_date = DB_DataObject_Cast::date($this->data['txtDate']); if ($election->insert()) { $this->bind(); $this->render(); } else { trigger_error("Unable to save election"); } } else { $this->bind(); $this->render(); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $AddIP, $userid, $group_ids; $apf_dailyreport = DB_DataObject::factory('ApfDailyreport'); if ($edit_submit) { $apf_dailyreport->get($apf_dailyreport->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_dailyreport->setTitle(stripslashes(trim($_POST['title']))); $apf_dailyreport->setContent(stripslashes(trim($_POST['content']))); $apf_dailyreport->setFilldate(stripslashes(trim($_POST['filldate']))); $apf_dailyreport->setActive(stripslashes(trim($_POST['active']))); $apf_dailyreport->setAddIp($AddIP); $apf_dailyreport->setGroupid($group_ids); $apf_dailyreport->setUserid($userid); $val = $apf_dailyreport->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_dailyreport->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_dailyreport->update(); $log_string = $i18n->_("Update") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("dailyreport/apf_dailyreport/update/" . $_POST['ID'] . "/ok"); } else { $apf_dailyreport->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_dailyreport->insert(); $log_string = $i18n->_("Create") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['create_date']}"; logFileString($log_string); $this->forward("dailyreport/apf_dailyreport/"); } } else { $template->setFile(array("MAIN" => "apf_dailyreport_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "FILL_DATE" => inputDateTag("filldate", $_POST['filldate']), "TEXTAREACONTENT" => textareaTag("content", $_POST['content'], true), "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "TITLE" => $_POST['title'], "CONTENT" => $_POST['content'], "FILLDATE" => $_POST['filldate'], "ACTIVE" => $_POST['active'], "GROUPID" => $_POST['groupid'], "USERID" => $_POST['userid'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n; $apf_product_price = DB_DataObject::factory('ApfProductPrice'); if ($edit_submit) { $apf_product_price->get($apf_product_price->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_product_price->setCompanyId(stripslashes(trim($_POST['company_id']))); $apf_product_price->setProductId(stripslashes(trim($_POST['product_id']))); $apf_product_price->setPrice(stripslashes(trim($_POST['price']))); $apf_product_price->setAddIp(stripslashes(trim($_POST['add_ip']))); $apf_product_price->setCreatedAt(stripslashes(trim($_POST['created_at']))); $apf_product_price->setUpdateAt(stripslashes(trim($_POST['update_at']))); $val = $apf_product_price->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_product_price->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_product_price->update(); $this->forward("product/apf_product_price/update/" . $_POST['ID'] . "/ok"); } else { $apf_product_price->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_product_price->insert(); $this->forward("product/apf_product_price/"); } } else { $template->setFile(array("MAIN" => "apf_product_price_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "COMPANY_ID" => $_POST['company_id'], "PRODUCT_ID" => $_POST['product_id'], "PRICE" => $_POST['price'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function create($args, $apidata) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); return; } $id = $apidata['api_arg']; $other = $this->get_user($id); if (!$other) { $this->clientError(_('Could not follow user: User not found.'), 403, $apidata['content-type']); return; } $user = $apidata['user']; if ($user->isSubscribed($other)) { $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); $this->clientError($errmsg, 403, $apidata['content-type']); return; } $sub = new Subscription(); $sub->query('BEGIN'); $sub->subscriber = $user->id; $sub->subscribed = $other->id; $sub->created = DB_DataObject_Cast::dateTime(); # current time $result = $sub->insert(); if (!$result) { $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); $this->clientError($errmsg, 400, $apidata['content-type']); return; } $sub->query('COMMIT'); mail_subscribe_notify($other, $user); $type = $apidata['content-type']; $this->init_document($type); $this->show_profile($other, $type); $this->end_document($type); }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n; $apf_groups = DB_DataObject::factory('ApfGroups'); if ($edit_submit) { $apf_groups->get($apf_groups->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_groups->setGroupType(stripslashes(trim($_POST['group_type']))); $apf_groups->setGroupDefineName(stripslashes(trim($_POST['group_define_name']))); $apf_groups->setIsActive(stripslashes(trim($_POST['is_active']))); $apf_groups->setOwnerUserId(stripslashes(trim($_POST['owner_user_id']))); $apf_groups->setOwnerGroupId(stripslashes(trim($_POST['owner_group_id']))); $val = $apf_groups->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_groups->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_groups->update(); $this->forward("users/apf_groups/update/" . $_POST['ID'] . "/ok"); } else { $apf_groups->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_groups->insert(); $this->forward("users/apf_groups/"); } } else { $template->setFile(array("MAIN" => "apf_groups_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("GROUP_ID" => $_POST['group_id'], "GROUP_TYPE" => $_POST['group_type'], "GROUP_DEFINE_NAME" => $_POST['group_define_name'], "IS_ACTIVE" => $_POST['is_active'], "OWNER_USER_ID" => $_POST['owner_user_id'], "OWNER_GROUP_ID" => $_POST['owner_group_id'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n; $apf_rights = DB_DataObject::factory('ApfRights'); if ($edit_submit) { $apf_rights->get($apf_rights->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_rights->setAreaId(stripslashes(trim($_POST['area_id']))); $apf_rights->setRightDefineName(stripslashes(trim($_POST['right_define_name']))); $apf_rights->setHasImplied(stripslashes(trim($_POST['has_implied']))); $val = $apf_rights->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_rights->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_rights->update(); $this->forward("users/apf_rights/update/" . $_POST['ID'] . "/ok"); } else { $apf_rights->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_rights->insert(); $this->forward("users/apf_rights/"); } } else { $template->setFile(array("MAIN" => "apf_rights_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("RIGHT_ID" => $_POST['right_id'], "AREA_ID" => $_POST['area_id'], "RIGHT_DEFINE_NAME" => $_POST['right_define_name'], "HAS_IMPLIED" => $_POST['has_implied'])); } }
/** * DateTime Constructor * * create a Cast object from a Date/Time * Maybe should accept a Date object.! * NO VALIDATION DONE, although some crappy re-calcing done! * * @param vargs... accepts * noargs (now) * yyyy-mm-dd HH:MM:SS (Iso) * array(yyyy,mm,dd,HH,MM,SS) * * * @return object DB_DataObject_Cast * @access public * @author therion 5 at hotmail */ function dateTime() { $args = func_get_args(); switch (count($args)) { case 0: // no args = now! $datetime = date('Y-m-d G:i:s', mktime()); case 1: // continue on from 0 args. if (!isset($datetime)) { $datetime = $args[0]; } $parts = explode(' ', $datetime); $bits = explode('-', $parts[0]); $bits = array_merge($bits, explode(':', $parts[1])); break; default: // 2 or more.. $bits = $args; } if (count($bits) != 6) { // PEAR ERROR? return false; } $r = DB_DataObject_Cast::date($bits[0], $bits[1], $bits[2]); if (!$r) { return $r; // pass thru error (False) - doesnt happen at present! } // change the type! $r->type = 'datetime'; // should we mathematically sort this out.. // (or just assume that no-one's dumb enough to enter 26:90:90 as a time! $r->hour = $bits[3]; $r->minute = $bits[4]; $r->second = $bits[5]; return $r; }
static function updateCount($d, $n) { $suc = Sitemap_user_count::getKV('registration_date', DB_DataObject_Cast::date($d)); if (empty($suc)) { // TRANS: Exception thrown when a registration date cannot be found. throw new Exception(_m("No such registration date: {$d}.")); } $orig = clone $suc; $suc->registration_date = DB_DataObject_Cast::date($d); $suc->user_count = $n; $suc->created = common_sql_now(); $suc->modified = $suc->created; if (!$suc->update($orig)) { common_log(LOG_WARNING, "Could not save user counts for '{$d}'"); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $luadmin, $ClassDir, $AllowUploadFilesType, $UploadDir; include_once 'HTTP/UploadProgressMeter.class.php'; $fileWidget = new UploadProgressMeter(); $fileWidget->name = 'photo'; if ($fileWidget->uploadComplete()) { $fileWidget->finalStatus(); } $apf_users = DB_DataObject::factory('ApfUsers'); if ($edit_submit) { $apf_users->get($apf_users->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_users->setUserName(stripslashes(trim($_POST['user_name']))); $apf_users->setRealname(stripslashes(trim($_POST['realname']))); $apf_users->setMemo(stripslashes(trim($_POST['memo']))); $apf_users->setGender(stripslashes(trim($_POST['gender']))); $apf_users->setAddrees(stripslashes(trim($_POST['addrees']))); $apf_users->setPhone(stripslashes(trim($_POST['phone']))); $apf_users->setEmail(stripslashes(trim($_POST['email']))); $apf_users->setRoleId(stripslashes(trim($_POST['role_id']))); $apf_users->setActive(stripslashes(trim($_POST['active']))); if ($_POST['photo_del'] == 'Y') { unlink($UploadDir . $_POST['photo_old']); $apf_users->setPhoto(""); $_POST['photo_old'] = ""; } if ($_POST['upload_temp']) { $apf_users->setPhoto($_POST['upload_temp']); } $allow_upload_file = TRUE; if ($_FILES['photo']['name']) { require_once $ClassDir . "FileHelper.class.php"; $upload_data = FileHelper::uploadFile("users"); $allow_upload_file = $upload_data["upload_state"]; if ($allow_upload_file) { $photos_arr = $upload_data["upload_msg"]; if ($photo_pic = $photos_arr['photo']) { $apf_users->setPhoto($photo_pic); $_POST['upload_temp'] = $photo_pic; } } else { $upload_error_msg = $upload_data["upload_msg"]; } } $val = $apf_users->validate(); if ($val === TRUE && $allow_upload_file === TRUE) { if ($edit_submit) { $apf_users->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_users->update(); $password = stripslashes(trim($_POST['user_pwd'])) ? stripslashes(trim($_POST['user_pwd'])) : stripslashes(trim($_POST['old_password'])); if (stripslashes(trim($_POST['user_pwd']))) { $data = array('handle' => stripslashes(trim($_POST['user_name'])), 'passwd' => $password); $updated = $luadmin->updateUser($data, $_POST['ID']); } //remove from group $filter = array('perm_user_id' => $_POST['ID'], 'group_id' => $_POST['old_group']); $luadmin->perm->removeUserFromGroup($filter); //add from group $data = array('perm_user_id' => $_POST['ID'], 'group_id' => $_POST['group']); $luadmin->perm->addUserToGroup($data); $this->forward("users/apf_users/update/" . $_POST['ID'] . "/ok"); } else { $data = array('handle' => stripslashes(trim($_POST['user_name'])), 'passwd' => stripslashes(trim($_POST['user_pwd'])), 'perm_type' => 1); $user_id = $luadmin->addUser($data); // add new group $data = array('perm_user_id' => $user_id, 'group_id' => $_POST['group']); $luadmin->perm->addUserToGroup($data); $apf_users->get($apf_users->escape($user_id)); // $apf_users->debugLevel(4); $apf_users->update(); $this->forward("users/apf_users/"); } } else { $template->setFile(array("MAIN" => "apf_users_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } if ($allow_upload_file !== TRUE) { $template->setVar(array("PHOTO_ERROR_MSG" => " ↓ {$upload_error_msg} ↓ ")); } $template->setVar(array("ID" => $_POST['id'], "USER_NAME" => $_POST['user_name'], "USER_PWD" => $_POST['user_pwd'], "GENDER" => $_POST['gender'], "ADDREES" => $_POST['addrees'], "PHONE" => $_POST['phone'], "EMAIL" => $_POST['email'], "PHOTO" => $_POST['photo'], "ROLE_ID" => $_POST['role_id'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function gravatar_save() { $cur = common_current_user(); if (empty($cur->email)) { return array('message' => _m('You do not have an email address set in your profile.'), 'success' => false); } //Get rid of previous Avatar $this->gravatar_remove(); foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { $gravatar = new Avatar(); $gravatar->profile_id = $cur->id; $gravatar->width = $size; $gravatar->height = $size; $gravatar->original = false; //No file, so no original $gravatar->mediatype = 'img'; //XXX: Unsure what to put here //$gravatar->filename = null;//No filename. Remote $gravatar->url = $this->gravatar_url($cur->email, $size); $gravatar->created = DB_DataObject_Cast::dateTime(); # current time if (!$gravatar->insert()) { return array('message' => _m('Failed to save Gravatar to the database.'), 'success' => false); } } return array('message' => _m('Gravatar added.'), 'success' => true); }
/** * DB_DataObject_FormBuilder::processForm() * * This will take the submitted form data and put it back into the object's properties. * If the primary key is not set or NULL, it will be assumed that you wish to insert a new * element into the database, so DataObject's insert() method is invoked. * Otherwise, an update() will be performed. * <i><b>Careful:</b> If you're using natural keys or cross-referencing tables where you don't have * one dedicated primary key, this will always assume that you want to do an update! As there * won't be a matching entry in the table, no action will be performed at all - the reason * for this behaviour can be very hard to detect. Thus, if you have such a situation in one * of your tables, simply override this method so that instead of the key check it will try * to do a SELECT on the table using the current settings. If a match is found, do an update. * If not, do an insert.</i> * This method is perfect for use with QuickForm's process method. Example: * <code> * if ($form->validate()) { * $form->freeze(); * $form->process(array(&$formGenerator,'processForm'), false); * } * </code> * * If you wish to enforce a special type of query, use the forceQueryType() method. * * Always remember to pass your objects by reference - otherwise, if the operation was * an insert, the primary key won't get updated with the new database ID because processForm() * was using a local copy of the object! * * If a method named "preProcessForm()" exists in your derived class, it will be called before * processForm() starts doing its magic. The data that has been submitted by the form * will be passed to that method as a parameter. * Same goes for a method named "postProcessForm()", with the only difference - you might * have guessed this by now - that it's called after the insert/update operations have * been done. Use this for filtering data, notifying users of changes etc.pp. ... * * @param array $values The values of the submitted form * @return mixed TRUE if database operations were performed, FALSE if not, PEAR_Error on error * @access public */ function processForm($values) { $origDo = clone $this->_do; if ($this->elementNamePrefix !== '' || $this->elementNamePostfix !== '') { $origValues = $values; $values = $this->_getMyValues($values); } $this->debug('<br>...processing form data...<br>'); if ($this->isCallableAndExists($this->preProcessFormCallback)) { call_user_func_array($this->preProcessFormCallback, array(&$values, &$this)); } $editableFields = array_intersect($this->_getUserEditableFields(), array_keys($this->_getFieldsToRender())); $tableFields = $this->_do->table(); if (!is_array($links = $this->_do->links())) { $links = array(); } foreach ($values as $field => $value) { $this->debug('Field ' . $field . ' '); // Double-check if the field may be edited by the user... if not, don't // set the submitted value, it could have been faked! if (in_array($field, $editableFields)) { if (isset($tableFields[$field])) { if ($tableFields[$field] & DB_DATAOBJECT_DATE || in_array($field, $this->dateFields)) { $this->debug('DATE CONVERSION for using callback from ' . $value . ' ...'); if ($this->isCallableAndExists($this->dateToDatabaseCallback)) { $value = call_user_func($this->dateToDatabaseCallback, $value); } else { $this->debug('WARNING: dateToDatabaseCallback not callable', 'FormBuilder'); } } elseif ($tableFields[$field] & DB_DATAOBJECT_TIME || in_array($field, $this->timeFields)) { $this->debug('TIME CONVERSION for using callback from ' . $value . ' ...'); if ($this->isCallableAndExists($this->dateToDatabaseCallback)) { $value = call_user_func($this->dateToDatabaseCallback, $value); } else { $this->debug('WARNING: dateToDatabaseCallback not callable', 'FormBuilder'); } } elseif (is_array($value)) { if (isset($value['tmp_name'])) { $this->debug(' (converting file array) '); $value = $value['name']; //JUSTIN //This is not really a valid assumption IMHO. This should only be done if the type is // date or the field is in dateFields /*} else { $this->debug("DATE CONVERSION using callback from $value ..."); $value = call_user_func($this->dateToDatabaseCallback, $value);*/ } } if (isset($links[$field])) { if ($value == $this->linkNewValueText && $tableFields[$field] & DB_DATAOBJECT_INT) { $value = 0; } elseif ($value === '') { $this->debug('Casting to NULL'); require_once 'DB/DataObject/Cast.php'; $value = DB_DataObject_Cast::sql('NULL'); } } $this->debug('is substituted with "' . print_r($value, true) . '".<br/>'); // See if a setter method exists in the DataObject - if so, use that one if ($this->useMutators && method_exists($this->_do, 'set' . $field)) { $this->_do->{'set' . $field}($value); } else { // Otherwise, just set the property 'normally'... $this->_do->{$field} = $value; } } else { $this->debug('is not a valid field.<br/>'); } } else { $this->debug('is defined not to be editable by the user!<br/>'); } } foreach ($this->booleanFields as $boolField) { if (in_array($boolField, $editableFields) && !isset($values[$boolField])) { if ($this->useMutators && method_exists($this->_do, 'set' . $boolField)) { $this->_do->{'set' . $boolField}(0); } else { $this->_do->{$boolField} = 0; } } } foreach ($tableFields as $field => $type) { if ($type & DB_DATAOBJECT_BOOL && in_array($field, $editableFields) && !isset($values[$field])) { if ($this->useMutators && method_exists($this->_do, 'set' . $field)) { $this->_do->{'set' . $field}(0); } else { $this->_do->{$field} = 0; } } } $dbOperations = true; if ($this->validateOnProcess === true) { $this->debug('Validating data... '); if (is_array($errors = $this->validateData())) { $dbOperations = false; } } $pk = $this->_getPrimaryKey($this->_do); // Data is valid, let's store it! if ($dbOperations) { //take care of linkNewValues /*if (isset($values['__DB_DataObject_FormBuilder_linkNewValue_'])) { foreach ($values['__DB_DataObject_FormBuilder_linkNewValue_'] as $elName => $subTable) {*/ if (isset($this->_form->_linkNewValueForms)) { foreach (array_keys($this->_form->_linkNewValueForms) as $elName) { $subTable = $this->_form->_linkNewValueDOs[$elName]->tableName(); if (isset($values['__DB_DataObject_FormBuilder_linkNewValue__' . $elName])) { if ($values[$elName] == $this->linkNewValueText) { //$this->_form->_prepareForLinkNewValue($elName, $subTable); $ret = $this->_form->_linkNewValueForms[$elName]->process(array(&$this->_form->_linkNewValueFBs[$elName], 'processForm'), false); if (PEAR::isError($ret)) { $this->debug('Error processing linkNewValue for ' . serialize($this->_form->_linkNewValueDOs[$elName])); return PEAR::raiseError('Error processing linkNewValue - Error from processForm: ' . $ret->getMessage(), null, null, null, $this->_form->_linkNewValueDOs[$elName]); } $subPk = $this->_form->_linkNewValueFBs[$elName]->_getPrimaryKey($this->_form->_linkNewValueDOs[$elName]); $this->_do->{$elName} = $values[$elName] = $this->_form->_linkNewValueDOs[$elName]->{$subPk}; } } } } $action = $this->_queryType; if ($this->_queryType == DB_DATAOBJECT_FORMBUILDER_QUERY_AUTODETECT) { // Could the primary key be detected? if ($pk === false) { // Nope, so let's exit and return false. Sorry, you can't store data using // processForm with this DataObject unless you do some tweaking :-( $this->debug('Primary key not detected - storing data not possible.'); return false; } $action = DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEUPDATE; if (!isset($this->_do->{$pk}) || !strlen($this->_do->{$pk})) { $action = DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT; } } switch ($action) { case DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT: if (false === ($id = $this->_do->insert())) { $this->debug('Insert of main record failed'); return $this->_raiseDoError('Insert of main record failed', $this->_do); } $this->debug('ID (' . $pk . ') of the new object: ' . $id . '<br/>'); break; case DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEUPDATE: if (false === $this->_do->update($origDo)) { $this->debug('Update of main record failed'); return $this->_raiseDoError('Update of main record failed', $this->_do); } $this->debug('Object updated.<br/>'); break; } // process tripleLinks foreach ($this->tripleLinks as $tripleLink) { $tripleLinkName = $this->_sanitizeFieldName('__tripleLink_' . $tripleLink['table'] . '_' . $tripleLink['fromField'] . '_' . $tripleLink['toField1'] . '_' . $tripleLink['toField2']); if (in_array($tripleLinkName, $editableFields)) { unset($do); $do = DB_DataObject::factory($tripleLink['table']); $fromField = $tripleLink['fromField']; $toField1 = $tripleLink['toField1']; $toField2 = $tripleLink['toField2']; if (isset($values[$tripleLinkName])) { $rows = $values[$tripleLinkName]; } else { $rows = array(); } $links = $do->links(); list($linkTable, $linkField) = explode(':', $links[$fromField]); $do->{$fromField} = $this->_do->{$linkField}; $do->selectAdd(); $do->selectAdd($toField1); $do->selectAdd($toField2); if ($doKey = $this->_getPrimaryKey($do)) { $do->selectAdd($doKey); } if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) { call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$do, $tripleLinkName)); } $oldFieldValues = array(); if ($do->find()) { while ($do->fetch()) { if (isset($rows[$do->{$toField1}]) && isset($rows[$do->{$toField1}][$do->{$toField2}])) { $oldFieldValues[$do->{$toField1}][$do->{$toField2}] = true; } else { if (false === $do->delete()) { $this->debug('Failed to delete tripleLink ' . serialize($do)); return $this->_raiseDoError('Failed to delete tripleLink', $do); } } } } if (count($rows) > 0) { foreach ($rows as $rowid => $row) { if (count($row) > 0) { foreach ($row as $fieldvalue => $on) { if (!isset($oldFieldValues[$rowid]) || !isset($oldFieldValues[$rowid][$fieldvalue])) { unset($do); $do = DB_DataObject::factory($tripleLink['table']); $do->{$fromField} = $this->_do->{$linkField}; $do->{$toField1} = $rowid; $do->{$toField2} = $fieldvalue; if (false === $do->insert()) { $this->debug('Failed to insert tripleLink ' . serialize($do)); return $this->_raiseDoError('Failed to insert tripleLink', $do); } } } } } } } } //process crossLinks foreach ($this->crossLinks as $crossLink) { $crossLinkName = $this->_sanitizeFieldName('__crossLink_' . $crossLink['table'] . '_' . $crossLink['fromField'] . '_' . $crossLink['toField']); if (in_array($crossLinkName, $editableFields)) { unset($do); $do = DB_DataObject::factory($crossLink['table']); $fromField = $crossLink['fromField']; $toField = $crossLink['toField']; if (isset($values[$crossLinkName])) { if ($crossLink['type'] == 'select') { $fieldvalues = array(); foreach ($values[$crossLinkName] as $value) { $fieldvalues[$value] = $value; } } else { $fieldvalues = $values[$crossLinkName]; } } else { $fieldvalues = array(); } /*if (isset($values['__crossLink_'.$crossLink['table'].'__extraFields'])) { $extraFieldValues = $values['__crossLink_'.$crossLink['table'].'__extraFields']; } else { $extraFieldValues = array(); }*/ $links = $do->links(); list($linkTable, $linkField) = explode(':', $links[$fromField]); $do->{$fromField} = $this->_do->{$linkField}; $do->selectAdd(); $do->selectAdd($toField); $do->selectAdd($fromField); if ($doKey = $this->_getPrimaryKey($do)) { $do->selectAdd($doKey); } if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) { call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$do, $crossLinkName)); } $oldFieldValues = array(); if ($do->find()) { while ($do->fetch()) { if (isset($fieldvalues[$do->{$toField}])) { $oldFieldValues[$do->{$toField}] = clone $do; } else { if (false === $do->delete()) { $this->debug('Failed to delete crossLink ' . serialize($do)); return $this->_raiseDoError('Failed to delete crossLink', $do); } } } } if (count($fieldvalues) > 0) { foreach ($fieldvalues as $fieldvalue => $on) { $crossLinkPrefix = $this->elementNamePrefix . $crossLinkName . '__' . $fieldvalue . '_'; $crossLinkPostfix = '_' . $this->elementNamePostfix; if (isset($oldFieldValues[$fieldvalue])) { if (isset($do->fb_crossLinkExtraFields) && (!isset($crossLink['type']) || $crossLink['type'] !== 'select')) { $ret = $this->_extraFieldsFb[$crossLinkPrefix . $crossLinkPostfix]->processForm(isset($origValues) ? $origValues : $values); if (PEAR::isError($ret)) { $this->debug('Failed to process extraFields for crossLink ' . serialize($do)); return PEAR::raiseError('Failed to process extraFields crossLink - Error from processForm: ' . $ret->getMessage(), null, null, null, $do); } } } else { if (isset($do->fb_crossLinkExtraFields) && (!isset($crossLink['type']) || $crossLink['type'] !== 'select')) { $insertValues = isset($origValues) ? $origValues : $values; $insertValues[$crossLinkPrefix . $fromField . $crossLinkPostfix] = $this->_do->{$linkField}; $insertValues[$crossLinkPrefix . $toField . $crossLinkPostfix] = $fieldvalue; $this->_extraFieldsFb[$crossLinkPrefix . $crossLinkPostfix]->fieldsToRender[] = $fromField; $this->_extraFieldsFb[$crossLinkPrefix . $crossLinkPostfix]->fieldsToRender[] = $toField; $ret = $this->_extraFieldsFb[$crossLinkPrefix . $crossLinkPostfix]->processForm($insertValues); if (PEAR::isError($ret)) { $this->debug('Failed to process extraFields for crossLink ' . serialize($do)); return PEAR::raiseError('Failed to process extraFields crossLink - Error from processForm: ' . $ret->getMessage(), null, null, null, $do); } } else { unset($do); $do = DB_DataObject::factory($crossLink['table']); $do->{$fromField} = $this->_do->{$linkField}; $do->{$toField} = $fieldvalue; if (false === $do->insert()) { $this->debug('Failed to insert crossLink ' . serialize($do)); return $this->_raiseDoError('Failed to insert crossLink', $do); } } } } } } } foreach ($this->reverseLinks as $reverseLink) { $elName = $this->_sanitizeFieldName('__reverseLink_' . $reverseLink['table'] . '_' . $reverseLink['field']); if (in_array($elName, $editableFields)) { // Check for subforms if (isset($this->linkElementTypes[$elName]) && $this->linkElementTypes[$elName] == 'subForm') { foreach ($reverseLink['SFs'] as $sfkey => $subform) { // Process each subform that was rendered. if ($subform->validate()) { $ret = $subform->process(array(&$reverseLink['FBs'][$sfkey], 'processForm'), false); if (PEAR::isError($ret)) { $this->debug('Failed to process subForm for reverseLink ' . serialize($reverseLink['FBs'][$sfkey]->_do)); return PEAR::raiseError('Failed to process extraFields crossLink - Error from processForm: ' . $ret->getMessage(), null, null, null, $reverseLink['FBs'][$sfkey]->_do); } } } } else { unset($do); $do = DB_DataObject::factory($reverseLink['table']); if ($this->isCallableAndExists($this->prepareLinkedDataObjectCallback)) { call_user_func_array($this->prepareLinkedDataObjectCallback, array(&$do, $key)); } if (!is_array($rLinks = $do->links())) { $rLinks = array(); } $rPk = $this->_getPrimaryKey($do); $rFields = $do->table(); list($lTable, $lField) = explode(':', $rLinks[$reverseLink['field']]); if ($do->find()) { while ($do->fetch()) { unset($newVal); if (isset($values[$elName][$do->{$rPk}])) { if ($do->{$reverseLink['field']} != $this->_do->{$lField}) { $do->{$reverseLink['field']} = $this->_do->{$lField}; if (false === $do->update()) { $this->debug('Failed to update reverseLink ' . serialize($do)); return $this->_raiseDoError('Failed to update reverseLink', $do); } } } elseif ($do->{$reverseLink['field']} == $this->_do->{$lField}) { if (isset($reverseLink['defaultLinkValue'])) { $do->{$reverseLink['field']} = $reverseLink['defaultLinkValue']; if (false === $do->update()) { $this->debug('Failed to update reverseLink ' . serialize($do)); return $this->_raiseDoError('Failed to update reverseLink', $do); } } else { if ($rFields[$reverseLink['field']] & DB_DATAOBJECT_NOTNULL) { //ERROR!! $this->debug('Checkbox in reverseLinks unset when link field may not be null'); } else { require_once 'DB/DataObject/Cast.php'; $do->{$reverseLink['field']} = DB_DataObject_Cast::sql('NULL'); if (false === $do->update()) { $this->debug('Failed to update reverseLink ' . serialize($do)); return $this->_raiseDoError('Failed to update reverseLink', $do); } } } } } } } } } } if ($this->isCallableAndExists($this->postProcessFormCallback)) { call_user_func_array($this->postProcessFormCallback, array(&$values, &$this)); } return $dbOperations; }
function setOriginal($filename) { $imagefile = new ImageFile($this->id, Avatar::path($filename)); $avatar = new Avatar(); $avatar->profile_id = $this->id; $avatar->width = $imagefile->width; $avatar->height = $imagefile->height; $avatar->mediatype = image_type_to_mime_type($imagefile->type); $avatar->filename = $filename; $avatar->original = true; $avatar->url = Avatar::url($filename); $avatar->created = DB_DataObject_Cast::dateTime(); # current time # XXX: start a transaction here if (!$this->delete_avatars() || !$avatar->insert()) { @unlink(Avatar::path($filename)); return null; } foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { # We don't do a scaled one if original is our scaled size if (!($avatar->width == $size && $avatar->height == $size)) { $scaled_filename = $imagefile->resize($size); //$scaled = DB_DataObject::factory('avatar'); $scaled = new Avatar(); $scaled->profile_id = $this->id; $scaled->width = $size; $scaled->height = $size; $scaled->original = false; $scaled->mediatype = image_type_to_mime_type($imagefile->type); $scaled->filename = $scaled_filename; $scaled->url = Avatar::url($scaled_filename); $scaled->created = DB_DataObject_Cast::dateTime(); # current time if (!$scaled->insert()) { return null; } } } return $avatar; }
function phpAds_ImageStore($type, $name, $buffer, $overwrite = false) { $aConf = $GLOBALS['_MAX']['CONF']; $pref = $GLOBALS['_MAX']['PREF']; // Make name web friendly $name = basename($name); $name = strtolower($name); $name = str_replace(" ", "_", $name); $name = str_replace("'", "", $name); $extension = substr($name, strrpos($name, ".")); if ($type == 'web') { $filename = phpAds_LocalUniqueName($buffer, $extension); if ($aConf['store']['mode'] == 'ftp') { // FTP mode $server = array(); $server['host'] = $aConf['store']['ftpHost']; $server['path'] = $aConf['store']['ftpPath']; if ($server['path'] != "" && substr($server['path'], 0, 1) == "/") { $server['path'] = substr($server['path'], 1); } $server['user'] = $aConf['store']['ftpUsername']; $server['pass'] = $aConf['store']['ftpPassword']; $server['passiv'] = !empty($aConf['store']['ftpPassive']); $stored_url = phpAds_FTPStore($server, $filename, $buffer, true); } else { // Local mode, get the unique filename $filename = phpAds_LocalUniqueName($buffer, $extension); // Doe the file exist already? if (@file_exists($aConf['store']['webDir'] . "/" . $filename) == false) { // Write the file if ($fp = @fopen($aConf['store']['webDir'] . "/" . $filename, 'wb')) { @fwrite($fp, $buffer); @fclose($fp); $stored_url = $filename; } } else { $stored_url = $filename; } } } if ($type == 'sql') { // Look for existing image. $doImages = OA_Dal::staticGetDO('images', $name); if ($doImages) { $doImages->contents = DB_DataObject_Cast::blob($buffer); if ($overwrite == false) { $name = $doImages->getUniqueFileNameForDuplication(); $doImages->filename = $name; $doImages->insert(); } else { $doImages->filename = $name; $doImages->update(); } } else { $doImages = OA_Dal::factoryDO('images'); $doImages->filename = $name; $doImages->contents = DB_DataObject_Cast::blob($buffer); $doImages->insert(); } $stored_url = $name; } if (isset($stored_url) && $stored_url != '') { return $stored_url; } else { return false; } }
function new_request_token($consumer, $callback) { $t = new Token(); $t->consumer_key = $consumer->key; $t->tok = common_good_rand(16); $t->secret = common_good_rand(16); $t->type = 0; // request $t->state = 0; // unauthorized $t->verified_callback = $callback; if ($callback === 'oob') { // six digit pin $t->verifier = mt_rand(0, 9999999); } else { $t->verifier = common_good_rand(8); } $t->created = DB_DataObject_Cast::dateTime(); if (!$t->insert()) { return null; } else { return new OAuthToken($t->tok, $t->secret); } }
$category->category_description = $category_description; if ($category->category_parent != $category_parent || $action == "add") { if ($category_parent > 0) { $q = $db->prepare("SELECT IFNULL(MAX(category_order), 0) AS ord FROM phph_categories WHERE category_parent = ?"); $res = $db->execute($q, $category_parent); } else { $q = $db->prepare("SELECT IFNULL(MAX(category_order)) AS ord FROM phph_categories WHERE category_parent IS NULL"); $res = $db->execute($q, $category_parent); } $row = $res->fetchRow(); $category->category_order = $row['ord'] + 1; } if ($category_parent > 0) { $category->category_parent = $category_parent; } else { $category->category_parent = DB_DataObject_Cast::sql("NULL"); } if ($action == "edit") { $r = $category->update(); } elseif ($action == "add") { $r = $category->insert(); } if (PEAR::isError($r)) { throw new Exception2(_INTERNAL_ERROR, $r->getMessage()); } if (!empty($ref)) { header("Location: " . $ref); } $pane = new HTML_MessagePane("upd", $action == "add" ? _ADMIN_CATEGORY_CREATED : _ADMIN_CATEGORY_UPDATED, "", "a_ok_pane", "a_ok_pane_hdr"); $pane->show(); } catch (Exception2 $e) {
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $UploadDir, $ClassDir, $AddIP, $userid, $group_ids; $apf_selfcompany = DB_DataObject::factory('ApfSelfcompany'); if ($edit_submit) { $apf_selfcompany->get($apf_selfcompany->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_selfcompany->setName(stripslashes(trim($_POST['name']))); $apf_selfcompany->setAddrees(stripslashes(trim($_POST['addrees']))); $apf_selfcompany->setPhone(stripslashes(trim($_POST['phone']))); $apf_selfcompany->setFax(stripslashes(trim($_POST['fax']))); $apf_selfcompany->setEmail(stripslashes(trim($_POST['email']))); $apf_selfcompany->setHomepage(stripslashes(trim($_POST['homepage']))); $apf_selfcompany->setEmployee(stripslashes(trim($_POST['employee']))); $apf_selfcompany->setBankroll(stripslashes(trim($_POST['bankroll']))); $apf_selfcompany->setLinkMan(stripslashes(trim($_POST['link_man']))); $apf_selfcompany->setIncorporator(stripslashes(trim($_POST['incorporator']))); $apf_selfcompany->setIndustry(stripslashes(trim($_POST['industry']))); $apf_selfcompany->setTaxaccounts(stripslashes(trim($_POST['taxaccounts']))); $apf_selfcompany->setBankaccounts(stripslashes(trim($_POST['bankaccounts']))); $apf_selfcompany->setProducts(stripslashes(trim($_POST['products']))); $apf_selfcompany->setMemo(stripslashes(trim($_POST['memo']))); $apf_selfcompany->setActive(stripslashes(trim($_POST['active']))); $apf_selfcompany->setAccess(stripslashes(trim($_POST['access']))); $apf_selfcompany->setAddIp($AddIP); $apf_selfcompany->setGroupid($group_ids); $apf_selfcompany->setUserid($userid); if ($_POST['photo_del'] == 'Y') { unlink($UploadDir . $_POST['photo_old']); $apf_selfcompany->setPhoto(""); $_POST['photo_old'] = ""; } if ($_POST['upload_temp']) { $apf_selfcompany->setPhoto($_POST['upload_temp']); } $allow_upload_file = TRUE; if ($_FILES['photo']['name']) { require_once $ClassDir . "FileHelper.class.php"; $upload_data = FileHelper::uploadFile("product"); $allow_upload_file = $upload_data["upload_state"]; if ($allow_upload_file) { $photos_arr = $upload_data["upload_msg"]; if ($photo_pic = $photos_arr['photo']) { $apf_selfcompany->setPhoto($photo_pic); $_POST['upload_temp'] = $photo_pic; } } else { $upload_error_msg = $upload_data["upload_msg"]; } } $val = $apf_selfcompany->validate(); if ($val === TRUE && $allow_upload_file === TRUE) { if ($edit_submit) { $apf_selfcompany->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_selfcompany->update(); $log_string = $i18n->_("Update") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("selfcompany/apf_selfcompany/update/" . $_POST['ID'] . "/ok"); } else { $apf_selfcompany->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_selfcompany->insert(); $log_string = $i18n->_("Create") . $i18n->_("ModuleName") . "\t{$_POST['name']}=>{$_POST['create_date']}"; logFileString($log_string); $this->forward("selfcompany/apf_selfcompany/"); } } else { $template->setFile(array("MAIN" => "apf_selfcompany_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "NAME" => $_POST['name'], "ADDREES" => $_POST['addrees'], "PHONE" => $_POST['phone'], "FAX" => $_POST['fax'], "EMAIL" => $_POST['email'], "PHOTO" => $_POST['photo'], "HOMEPAGE" => $_POST['homepage'], "EMPLOYEE" => $_POST['employee'], "BANKROLL" => $_POST['bankroll'], "LINK_MAN" => $_POST['link_man'], "INCORPORATOR" => $_POST['incorporator'], "INDUSTRY" => $_POST['industry'], "TAXACCOUNTS" => $_POST['taxaccounts'], "BANKACCOUNTS" => $_POST['bankaccounts'], "PRODUCTS" => $_POST['products'], "MEMO" => $_POST['memo'], "ACTIVE" => $_POST['active'], "ACCESS" => $_POST['access'], "GROUPID" => $_POST['groupid'], "USERID" => $_POST['userid'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption, $ClassDir, $UploadDir, $AllowUploadFilesType, $AddIP, $userid, $group_ids; $apf_product = DB_DataObject::factory('ApfProduct'); if ($edit_submit) { $apf_product->get($apf_product->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_product->setCategory(stripslashes(trim($_POST['category']))); $apf_product->setCompanyId(stripslashes(trim($_POST['company_id']))); $apf_product->setName(stripslashes(trim($_POST['name']))); $apf_product->setPrice(stripslashes(trim($_POST['price']))); $apf_product->setMemo(stripslashes(trim($_POST['memo']))); $apf_product->setActive(stripslashes(trim($_POST['active']))); $apf_product->setAddIp($AddIP); $apf_product->setGroupid($group_ids); $apf_product->setUserid($userid); if ($_POST['photo_del'] == 'Y') { unlink($UploadDir . $_POST['photo_old']); $apf_product->setPhoto(""); $_POST['photo_old'] = ""; } if ($_POST['upload_temp']) { $apf_product->setPhoto($_POST['upload_temp']); } $allow_upload_file = TRUE; if ($_FILES['photo']['name']) { require_once $ClassDir . "FileHelper.class.php"; $upload_data = FileHelper::uploadFile("product"); $allow_upload_file = $upload_data["upload_state"]; if ($allow_upload_file) { $photos_arr = $upload_data["upload_msg"]; if ($photo_pic = $photos_arr['photo']) { $apf_product->setPhoto($photo_pic); $_POST['upload_temp'] = $photo_pic; } } else { $upload_error_msg = $upload_data["upload_msg"]; } } $val = $apf_product->validate(); if ($val === TRUE && $allow_upload_file === TRUE) { if ($edit_submit) { $apf_product->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_product->update(); $log_string = $i18n->_("Update") . $i18n->_("Product") . "\t{$_POST['name']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("product/apf_product/update/" . $_POST['ID'] . "/ok"); } else { $apf_product->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_product->insert(); $log_string = $i18n->_("Create") . $i18n->_("Product") . "\t{$_POST['name']}"; logFileString($log_string); $this->forward("product/apf_product/"); } } else { $template->setFile(array("MAIN" => "apf_product_edit.html")); $template->setBlock("MAIN", "edit_block"); $template->setVar(array("WEBDIR" => $WebBaseDir, "DOACTION" => $do_action)); $category_arr = $this->getCategory(); array_shift($ActiveOption); $template->setVar(array("CATEGORYOPTION" => selectTag("category", $category_arr, $_POST['category']), "FILEPHOTO" => fileTag("photo", $_POST['photo_old']), "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']))); foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ ")); } } $template->setVar(array("ID" => $_POST['id'], "CATEGORY" => $_POST['category'], "COMPANY_ID" => $_POST['company_id'], "NAME" => $_POST['name'], "PRICE" => $_POST['price'], "PHOTO" => $_POST['photo'], "MEMO" => $_POST['memo'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
/** * Save a subscription * * Saves the subscription from $subscriber_uri to $subscribed_user_uri. * Throws exceptions in case of error. * * @param string $subscriber_uri The OMB identifier URI specifying * the subscribing profile * * @param string $subscribed_user_uri The OMB identifier URI specifying * the subscribed profile * @param OAuthToken $token The access token * * @access public **/ public function saveSubscription($subscriber_uri, $subscribed_user_uri, $token) { $sub = new Subscription(); $subscribed = $this->_getAnyProfile($subscribed_user_uri); $subscriber = $this->_getAnyProfile($subscriber_uri); if (!$subscriber->hasRight(Right::SUBSCRIBE)) { common_log(LOG_INFO, __METHOD__ . ": remote subscriber banned ({$subscriber_uri} subbing to {$subscribed_user_uri})"); // TRANS: Error message displayed to a banned user when they try to subscribe. return _('You have been banned from subscribing.'); } $sub->subscribed = $subscribed->id; $sub->subscriber = $subscriber->id; $sub_exists = $sub->find(true); if ($sub_exists) { $orig_sub = clone $sub; } else { $sub->created = DB_DataObject_Cast::dateTime(); } $sub->token = $token->key; $sub->secret = $token->secret; if ($sub_exists) { $result = $sub->update($orig_sub); } else { $result = $sub->insert(); } if (!$result) { common_log_db_error($sub, $sub_exists ? 'UPDATE' : 'INSERT', __FILE__); // TRANS: Exception thrown when creating a new subscription fails in OAuth store. throw new Exception(_('Could not insert new subscription.')); return; } /* Notify user, if necessary. */ if ($subscribed instanceof User) { mail_subscribe_notify_profile($subscribed, Profile::staticGet($subscriber->id)); } }
function handleSubmit() { unset($_SESSION['openid_trust_root']); unset($_SESSION['openid_allow_url']); unset($_SESSION['openid_deny_url']); if ($this->arg('allow')) { //save to database $user_openid_trustroot = new User_openid_trustroot(); $user_openid_trustroot->user_id = $this->user->id; $user_openid_trustroot->trustroot = $this->trust_root; $user_openid_trustroot->created = DB_DataObject_Cast::dateTime(); if (!$user_openid_trustroot->insert()) { $err = PEAR::getStaticProperty('DB_DataObject', 'lastError'); } common_redirect($this->allowUrl, $code = 302); } else { common_redirect($this->denyUrl, $code = 302); } }
function new_access_token($token, $consumer) { common_debug('new_access_token("' . $token->key . '","' . $consumer->key . '")', __FILE__); $rt = new Token(); $rt->consumer_key = $consumer->key; $rt->tok = $token->key; $rt->type = 0; // request $app = Oauth_application::getByConsumerKey($consumer->key); if (empty($app)) { common_debug("empty app!"); } if ($rt->find(true) && $rt->state == 1) { // authorized common_debug('request token found.', __FILE__); // find the associated user of the app $appUser = new Oauth_application_user(); $appUser->application_id = $app->id; $appUser->token = $rt->tok; $result = $appUser->find(true); if (!empty($result)) { common_debug("Oath app user found."); } else { common_debug("Oauth app user not found. app id {$app->id} token {$rt->tok}"); return null; } // go ahead and make the access token $at = new Token(); $at->consumer_key = $consumer->key; $at->tok = common_good_rand(16); $at->secret = common_good_rand(16); $at->type = 1; // access $at->created = DB_DataObject_Cast::dateTime(); if (!$at->insert()) { $e = $at->_lastError; common_debug('access token "' . $at->tok . '" not inserted: "' . $e->message . '"', __FILE__); return null; } else { common_debug('access token "' . $at->tok . '" inserted', __FILE__); // burn the old one $orig_rt = clone $rt; $rt->state = 2; // used if (!$rt->update($orig_rt)) { return null; } common_debug('request token "' . $rt->tok . '" updated', __FILE__); // update the token from req to access for the user $orig = clone $appUser; $appUser->token = $at->tok; // It's at this point that we change the access type // to whatever the application's access is. Request // tokens should always have an access type of 0, and // therefore be unuseable for making requests for // protected resources. $appUser->access_type = $app->access_type; $result = $appUser->update($orig); if (empty($result)) { common_debug('couldn\'t update OAuth app user.'); return null; } // Okay, good return new OAuthToken($at->tok, $at->secret); } } else { return null; } }