示例#1
0
 function addDashlet()
 {
     if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php')) {
         require_once 'include/Dashlets/DashletCacheBuilder.php';
         $dc = new DashletCacheBuilder();
         $dc->buildCache();
     }
     require_once $GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php';
     global $current_user;
     if (isset($_REQUEST['id'])) {
         $pages = $current_user->getPreference('pages', $this->type);
         $dashlets = $current_user->getPreference('dashlets', $this->type);
         $guid = create_guid();
         if (isset($_REQUEST['type_module'])) {
             $dashlet_module = $_REQUEST['type_module'];
         } elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
             $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
         } else {
             $dashlet_module = 'Home';
         }
         $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'], 'module' => $dashlet_module, 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
         // add to beginning of the array
         array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
         $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
         echo $guid;
     } else {
         echo 'ofdaops';
     }
 }
示例#2
0
 public function pre_save()
 {
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile('filename_file');
     if (isset($_FILES['filename_file']) && $upload_file->confirm_upload()) {
         $filename = $upload_file->get_stored_file_name();
         $file_ext = $upload_file->file_ext;
         if (empty($this->bean->id)) {
             $this->bean->id = create_guid();
             $this->bean->new_with_id = true;
         }
         $account = null;
         if (isset($_POST['xphotobucketaccount_id'])) {
             $account = BeanFactory::getBean('xPhotobucketAccounts', $_POST['xphotobucketaccount_id']);
         }
         // $resp = $account->upload_media('image', $upload_file->temp_file_location, "{$this->bean->id}.{$file_ext}", $_POST['name']);
         $resp = $account->upload_media('base64', base64_encode(file_get_contents($upload_file->temp_file_location)), "{$this->bean->id}.{$file_ext}", $_POST['name']);
         $this->bean->browse_url = $resp['browseurl'];
         $this->bean->image_url = $resp['url'];
         $this->bean->thumb_url = $resp['thumb'];
     } else {
         echo "Upload file error";
         sugar_cleanup(true);
     }
     parent::pre_save();
 }
 protected function createUser($userData)
 {
     $user = new User();
     $user->user_name = $userData['email'];
     $user->email = $userData['email'];
     $user->email1 = $userData['email'];
     $user->first_name = $userData['first_name'];
     $user->last_name = $userData['last_name'];
     $user->status = 'Active';
     $user->is_admin = 0;
     $user->external_auth_only = 1;
     $user->system_generated_password = 0;
     $user->authenticate_id = $userData['remote_id'];
     $user->receive_notifications = 0;
     if (!empty($userData['photo'])) {
         $picid = create_guid();
         if (copy($userData['photo'], "upload://{$picid}")) {
             $user->picture = $picid;
         }
     }
     $user->id = 'rmt-' . md5($userData['remote_id']);
     $user->new_with_id = true;
     $user->save();
     $user->setPreference('ut', 1);
     $user->savePreferencesToDB();
     return $user->id;
 }
示例#4
0
 public function testRepairXSSNotDuplicating()
 {
     $this->note1 = new Note();
     $this->note1->id = create_guid();
     $this->note1->new_with_id = true;
     $this->note1->name = "[Bug47069] Not deleted Note";
     $this->note1->description = "This note shouldn't be deleted.";
     $this->note1->save();
     $this->note2 = new Note();
     $this->note2->id = create_guid();
     $this->note2->new_with_id = true;
     $this->note2->name = "[Bug47069] Deleted Note";
     $this->note2->description = "This note should be deleted.";
     $this->note2->deleted = 1;
     $this->note2->save();
     ob_start();
     $_REQUEST['adminAction'] = 'refreshEstimate';
     $_REQUEST['bean'] = 'Notes';
     require_once 'modules/Administration/Async.php';
     $firstEstimate = $out;
     ob_end_clean();
     ob_start();
     $_REQUEST['adminAction'] = 'repairXssExecute';
     $_REQUEST['bean'] = 'Notes';
     $_REQUEST['id'] = json_encode(array($this->note1->id, $this->note2->id));
     require_once 'modules/Administration/Async.php';
     ob_end_clean();
     ob_start();
     $_REQUEST['adminAction'] = 'refreshEstimate';
     $_REQUEST['bean'] = 'Notes';
     require_once 'modules/Administration/Async.php';
     $secondEstimate = $out;
     ob_end_clean();
     $this->assertEquals($firstEstimate['count'], $secondEstimate['count'], 'The record count should not increase after a repair XSS');
 }
 public function generateLayout($thisLayout, $height)
 {
     $layoutGuid = create_guid();
     //$layoutString = '<script type="text/javascript" src="modules/KReports/javascript/kreportsvisualizationmanager.js"></script>';
     // write the registry
     if (count($this->pluginRegistry) > 0) {
         $layoutString .= '<script type="text/javascript">K.kreports.visualizationmanager.myID="vis' . $layoutGuid . '";K.kreports.visualizationmanager.registeredPlugins=' . json_encode($this->pluginRegistry) . '</script>';
     }
     // write the header data
     foreach ($this->headerData as $plugin => $pluginData) {
         $layoutString .= $pluginData['object']->getHeader();
     }
     $layoutString .= "<div id='vis" . $layoutGuid . "' style='margin-top: 5px;position: relative;height:" . $height . "px;'>";
     for ($i = 0; $i < count($this->layouts[$thisLayout]['items']); $i++) {
         if (isset($this->itemData[$i + 1])) {
             $layoutString .= "<div id='" . $this->itemData[$i + 1]['divID'] . "' style='position:absolute;" . "top:" . $this->layouts[$thisLayout]['items'][$i]['top'] . ";" . "left:" . $this->layouts[$thisLayout]['items'][$i]['left'] . ";" . "height:" . $this->layouts[$thisLayout]['items'][$i]['height'] . ";" . "width:" . $this->layouts[$thisLayout]['items'][$i]['width'] . ($this->layouts[$thisLayout]['items'][$i]['style'] != '' ? '; ' . $this->layouts[$thisLayout]['items'][$i]['style'] : '') . "'></div>";
             $layoutString .= $this->itemData[$i + 1]['addDivData'];
             $layoutString .= $this->itemData[$i + 1]['content'];
         } else {
             $layoutString .= "<div id='vis" . $layoutGuid . "_" . $i . "' style='position:absolute;border: 2px solid white;background:grey;" . "top:" . $this->layouts[$thisLayout]['items'][$i]['top'] . ";" . "left:" . $this->layouts[$thisLayout]['items'][$i]['left'] . ";" . "height:" . $this->layouts[$thisLayout]['items'][$i]['height'] . ";" . "width:" . $this->layouts[$thisLayout]['items'][$i]['width'] . ($this->layouts[$thisLayout]['items'][$i]['style'] != '' ? '; ' . $this->layouts[$thisLayout]['items'][$i]['style'] : '') . "'></div>";
         }
     }
     $layoutString .= "</div>";
     return $layoutString;
 }
 public function run()
 {
     // are we coming from 6.7 but before 7.0
     if (!version_compare($this->from_version, '6.7.0', '>=') || !version_compare($this->from_version, '7.0', '<')) {
         return;
     }
     // we need to anything other than ENT and ULT
     if (!$this->fromFlavor('pro')) {
         return;
     }
     $this->log('Creating Forecast Worksheet Draft Records');
     $sql = "SELECT '' as id, " . "fw.name, " . "fw.date_entered, " . "fw.date_modified, " . "fw.modified_user_id, " . "fw.created_by, " . "fw.description, " . "fw.deleted, " . "fw.assigned_user_id, " . "fw.team_id, " . "fw.team_set_id, " . "fw.parent_id, " . "fw.parent_type, " . "fw.likely_case, " . "fw.best_case, " . "fw.worst_case, " . "fw.base_rate, " . "fw.currency_id, " . "fw.date_closed, " . "fw.date_closed_timestamp, " . "fw.sales_stage, " . "fw.probability, " . "fw.commit_stage, " . "1 as draft, " . "fw.opportunity_id, " . "fw.opportunity_name, " . "fw.account_name, " . "fw.account_id, " . "fw.campaign_id, " . "fw.campaign_name, " . "fw.product_template_id, " . "fw.product_template_name, " . "fw.category_id, " . "fw.category_name, " . "fw.sales_status, " . "fw.next_step, " . "fw.lead_source, " . "fw.product_type, " . "fw.list_price, " . "fw.cost_price, " . "fw.discount_price, " . "fw.discount_amount, " . "fw.quantity, " . "fw.total_amount " . "FROM forecast_worksheets fw " . "LEFT JOIN forecast_worksheets fw2 " . "ON fw.parent_type = fw2.parent_type " . "AND fw.parent_id = fw2.parent_id " . "AND fw2.draft = 1 " . "WHERE fw.deleted = 0 " . "AND fw.draft = 0 " . "AND fw2.id IS NULL";
     $results = $this->db->query($sql);
     $insertSQL = 'INSERT INTO forecast_worksheets ';
     /* @var $fw ForecastWorksheet */
     $fw = BeanFactory::getBean('ForecastWorksheets');
     while ($row = $this->db->fetchByAssoc($results)) {
         $row['id'] = create_guid();
         foreach ($row as $key => $value) {
             $fieldDefs = $fw->getFieldDefinition($key);
             $convertedValue = $this->db->fromConvert($value, $this->db->getFieldType($fieldDefs));
             $row[$key] = $this->db->massageValue($convertedValue, $fieldDefs);
         }
         $this->db->query($insertSQL . '(' . join(',', array_keys($row)) . ') VALUES (' . join(',', $row) . ');');
     }
     $this->log('Done Creating Forecast Worksheet Draft Records');
 }
示例#7
0
 /**
  * Maps Quote Values to the Opportunity
  *
  * @param Quote $quote
  * @param Opportunity $opp
  */
 protected function mapQuoteToOpportunity(Quote $quote, Opportunity $opp)
 {
     // @codeCoverageIgnoreStart
     global $app_list_strings;
     // @codeCoverageIgnoreEnd
     $forecastConfig = $this->getForecastConfig();
     $opp->id = create_guid();
     $opp->new_with_id = true;
     $opp->assigned_user_id = $quote->assigned_user_id;
     $opp->date_closed = $quote->date_quote_expected_closed;
     $opp->name = $quote->name;
     $opp->assigned_user_name = $quote->assigned_user_name;
     $opp->lead_source = isset($app_list_strings['lead_source_dom']['Self Generated']) ? 'Self Generated' : null;
     $opp->opportunity_type = isset($app_list_strings['opportunity_type_dom']['New Business']) ? $app_list_strings['opportunity_type_dom']['New Business'] : null;
     $opp->team_id = $quote->team_id;
     // TODO: this will need to change when we have the switch for Opportunities,
     // TODO: but since that is not done yet this will use the forecast_by.
     if ($forecastConfig['forecast_by'] == 'Opportunities') {
         // just setting sales_stage will now set probability correctly
         $opp->sales_stage = isset($app_list_strings['sales_stage_dom']['Proposal/Price Quote']) ? 'Proposal/Price Quote' : null;
         $opp->amount = $quote->total;
     }
     $opp->quote_id = $quote->id;
     $opp->currency_id = $quote->currency_id;
     $opp->base_rate = $quote->base_rate;
     $opp->account_id = $quote->billing_account_id;
     // save the opp so we can add the products to it.
     $opp->save();
 }
示例#8
0
 public function setUp()
 {
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     $this->_account = new Account();
     $this->_account->name = 'Account_' . create_guid();
     $this->_account->save();
 }
示例#9
0
 /**
  * Saves a file to a module field using the PUT method
  *
  * @param ServiceBase $api  The service base
  * @param array       $args Arguments array built by the service base
  * @param string      $stream
  *
  * @throws SugarApiExceptionMissingParameter
  * @return array
  */
 public function saveFilePut($api, $args, $stream = 'php://input')
 {
     // Mime type, set to null for grabbing it later if not sent
     $filetype = isset($_SERVER['HTTP_CONTENT_TYPE']) ? $_SERVER['HTTP_CONTENT_TYPE'] : null;
     // Set the filename, first from the passed args then from the request itself
     if (isset($args['filename'])) {
         $filename = $args['filename'];
     } else {
         $filename = isset($_SERVER['HTTP_FILENAME']) ? $_SERVER['HTTP_FILENAME'] : create_guid();
     }
     // Legacy support for base64 encoded file data
     $encoded = $this->isFileEncoded($api, $args);
     // Create a temp name for our file to begin mocking the $_FILES array
     $tempfile = $this->getTempFileName();
     $this->createTempFileFromInput($tempfile, $stream, $encoded);
     // Now validate our file
     $filesize = filesize($tempfile);
     $this->checkPutRequestBody($filesize);
     // Now get our actual mime type from our internal methodology if it wasn't passed
     if (empty($filetype)) {
         require_once 'include/download_file.php';
         $dl = new DownloadFileApi($api);
         $filetype = $dl->getMimeType($tempfile);
     }
     // Mock a $_FILES array member, adding in _SUGAR_API_UPLOAD to allow file uploads
     $_FILES[$args['field']] = array('name' => $filename, 'type' => $filetype, 'tmp_name' => $tempfile, 'error' => 0, 'size' => $filesize, '_SUGAR_API_UPLOAD' => true);
     // Now that we are set up, hand this off to the POST save handler
     $return = $this->saveFilePost($api, $args);
     // Handle temp file cleanup
     if (file_exists($tempfile)) {
         unlink($tempfile);
     }
     // Send back our result
     return $return;
 }
示例#10
0
 function start()
 {
     $this->db = DBManagerFactory::getInstance();
     $this->userDemoData = new UserDemoData($this->user, false);
     $this->trackerManager = TrackerManager::getInstance();
     foreach ($this->modules as $mod) {
         $query = "select id from {$mod}";
         $result = $this->db->limitQuery($query, 0, 50);
         $ids = array();
         while ($row = $this->db->fetchByAssoc($result)) {
             $ids[] = $row['id'];
         }
         //while
         $this->beanIdMap[$mod] = $ids;
     }
     while ($this->monitorIds-- > 0) {
         $this->monitorId = create_guid();
         $this->trackerManager->setMonitorId($this->monitorId);
         $this->user = $this->userDemoData->guids[array_rand($this->userDemoData->guids)];
         $this->module = $this->modules[array_rand($this->modules)];
         $this->action = $this->actions[array_rand($this->actions)];
         $this->date = $this->randomTimestamp();
         $this->populate_tracker();
         $this->populate_tracker_perf();
         $this->populate_tracker_sessions();
         $this->populate_tracker_queries();
         $this->trackerManager->save();
     }
 }
示例#11
0
 public function save(&$bean, $params, $field, $vardef, $prefix = '')
 {
     $fakeDisplayParams = array();
     $this->fillInOptions($vardef, $fakeDisplayParams);
     require_once 'include/upload_file.php';
     $upload_file = new UploadFile($prefix . $field . '_file');
     //remove file
     if (isset($_REQUEST['remove_file_' . $field]) && $params['remove_file_' . $field] == 1) {
         $upload_file->unlink_file($bean->{$field});
         $bean->{$field} = "";
     }
     $move = false;
     if (isset($_FILES[$prefix . $field . '_file']) && $upload_file->confirm_upload()) {
         if ($this->verify_image($upload_file)) {
             $bean->{$field} = $upload_file->get_stored_file_name();
             $move = true;
         } else {
             //not valid image.
             $GLOBALS['log']->fatal("Image Field : Not a Valid Image.");
             $temp = $vardef['vname'];
             $temp = translate($temp, $bean->module_name);
             SugarApplication::appendErrorMessage($temp . " Field :  Not a valid image format.");
         }
     }
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     if ($move) {
         $upload_file->final_move($bean->id . '_' . $field);
         //BEAN ID IS THE FILE NAME IN THE INSTANCE.
         $upload_file->upload_doc($bean, $bean->id, $params[$prefix . $vardef['docType']], $bean->{$field}, $upload_file->mime_type);
     } else {
         if (!empty($old_id)) {
             // It's a duplicate, I think
             if (empty($params[$prefix . $vardef['docUrl']])) {
                 $upload_file->duplicate_file($old_id, $bean->id, $bean->{$field});
             } else {
                 $docType = $vardef['docType'];
                 $bean->{$docType} = $params[$prefix . $field . '_old_doctype'];
             }
         } else {
             if (!empty($params[$prefix . $field . '_remoteName'])) {
                 // We aren't moving, we might need to do some remote linking
                 $displayParams = array();
                 $this->fillInOptions($vardef, $displayParams);
                 if (isset($params[$prefix . $vardef['docId']]) && !empty($params[$prefix . $vardef['docId']]) && isset($params[$prefix . $vardef['docType']]) && !empty($params[$prefix . $vardef['docType']])) {
                     $bean->{$field} = $params[$prefix . $field . '_remoteName'];
                     require_once 'include/utils/file_utils.php';
                     $extension = get_file_extension($bean->{$field});
                     if (!empty($extension)) {
                         $bean->file_ext = $extension;
                         $bean->file_mime_type = get_mime_content_type_from_filename($bean->{$field});
                     }
                 }
             }
         }
     }
 }
示例#12
0
 /**
  * Test asserts that fetched row has more priority then property
  *
  * @group 60442
  * @return void
  */
 public function testIsOwner()
 {
     $bean = new SugarBean();
     $bean->id = create_guid();
     $bean->fetched_row['assigned_user_id'] = 1;
     $bean->assigned_user_id = 2;
     $this->assertTrue($bean->isOwner(1), 'Incorrect ownership');
 }
示例#13
0
 function Node($id, $label, $show_expanded = false)
 {
     $this->_label = $label;
     $this->_properties['label'] = $label;
     $this->uid = create_guid();
     $this->set_property('id', $id);
     $this->expanded = $show_expanded;
 }
示例#14
0
 /**
  * inserts default (usually US Dollar) as default currency
  */
 function insertDefaults()
 {
     global $sugar_config;
     $insert = true;
     if ($insert) {
         $q = "INSERT INTO currencies (id, name, symbol, iso4217, conversion_rate, status, deleted, date_entered, date_modified, created_by)\n\t\t\t\t\tVALUES('" . create_guid() . "', \n\t\t\t\t\t\t'{$sugar_config['default_currency_name']}',\n\t\t\t\t\t\t'{$sugar_config['default_currency_symbol']}',\n\t\t\t\t\t\t'{$sugar_config['default_currency_iso4217']}',\n\t\t\t\t\t\t1.0, 'Active', 0, '" . date($GLOBALS['timedate']->get_db_date_time_format()) . "', '" . date($GLOBALS['timedate']->get_db_date_time_format()) . "', '1')";
     }
 }
示例#15
0
 function setRelationship($fit_id, $account_id)
 {
     global $db;
     $id = create_guid();
     // Tao ID cho relate record theo chuan cua Sugar
     $queryIns = "   INSERT INTO accounts_fits_c\r\n                            VALUES (\r\n                                '" . $id . "',\r\n                                NOW(),\r\n                                0,\r\n                                '" . $account_id . "',\r\n                                '" . $fit_id . "'\r\n                            )";
     $db->query($queryIns);
 }
示例#16
0
 function onSave(&$bean)
 {
     $query = "SELECT id\n                    FROM calls_users\n                    WHERE\n                        deleted <> 1 AND\n                        call_id='{$bean->id}' AND\n                        user_id='{$bean->assigned_user_id}'";
     $result = $bean->db->query($query);
     if (!($row = $bean->db->fetchByAssoc($result))) {
         $query = "INSERT INTO calls_users\n\t\t\t\t\t\t(id, call_id, user_id, deleted, required, accept_status, date_modified)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('" . create_guid() . "', '{$bean->id}', '{$bean->assigned_user_id}', 0, 1, 'none', '" . date('Y-m-d H:i:s') . "')\n\t\t\t\t\t";
         $result = $bean->db->query($query);
     }
 }
示例#17
0
 /**
  * @deprecated
  * @param string $bundle_id
  * @param string $product_id
  * @param string $note_id
  * @param integer $note_index
  */
 public function set_product_bundle_product_notes_relationship($bundle_id, $product_id, $note_id = '', $note_index)
 {
     if (empty($note_id)) {
         $note_id = $this->id;
     }
     $query = "INSERT INTO {$this->rel_notes} SET id='" . create_guid() . "', bundle_id='" . $bundle_id . "', product_id='" . $product_id . "', note_id='" . $note_id . "', note_index='" . $note_index . "'";
     $this->db->query($query, true, "Error setting note to product to product bundle relationship: " . "<BR>{$query}");
     $GLOBALS['log']->debug("Setting note to product to product bundle relationship for bundle_id: {$bundle_id}, product_id: {$product_id}, and note_id: {$note_id}");
 }
示例#18
0
 function send_email($module, $module_type, $printable, $file_name, $attach)
 {
     require_once 'modules/Emails/Email.php';
     global $current_user, $mod_strings, $sugar_config;
     //First Create e-mail draft
     $email = new Email();
     // set the id for relationships
     $email->id = create_guid();
     $email->new_with_id = true;
     //subject
     $email->name = $mod_strings['LBL_EMAIL_NAME'] . ' ' . $module->name;
     //body
     $email->description_html = $printable;
     //type is draft
     $email->type = "draft";
     $email->status = "draft";
     if (!empty($module->billing_contact_id) && $module->billing_contact_id != "") {
         require_once 'modules/Contacts/Contact.php';
         $contact = new Contact();
         $contact->retrieve($module->billing_contact_id);
         $email->parent_type = 'Contacts';
         $email->parent_id = $contact->id;
         if (!empty($contact->email1)) {
             $email->to_addrs_emails = $contact->email1 . ";";
             $email->to_addrs = $module->billing_contact_name . " <" . $contact->email1 . ">";
         }
     }
     //team id
     $email->team_id = $current_user->default_team;
     //assigned_user_id
     $email->assigned_user_id = $current_user->id;
     //Save the email object
     global $timedate;
     $email->date_start = $timedate->to_display_date_time(gmdate($GLOBALS['timedate']->get_db_date_time_format()));
     $email->save(FALSE);
     $email_id = $email->id;
     if ($attach) {
         $note = new Note();
         $note->modified_user_id = $current_user->id;
         $note->created_by = $current_user->id;
         $note->name = $file_name;
         $note->parent_type = 'Emails';
         $note->parent_id = $email_id;
         $note->file_mime_type = 'application/pdf';
         $note->filename = $file_name;
         $note->save();
         rename($sugar_config['upload_dir'] . 'attachfile.pdf', $sugar_config['upload_dir'] . $note->id);
     }
     //redirect
     if ($email_id == "") {
         echo "Unable to initiate Email Client";
         exit;
     } else {
         header("Location: index.php?action=Compose&module=Emails&return_module=" . $module_type . "&return_action=DetailView&return_id=" . $_REQUEST['record'] . "&recordId=" . $email_id);
     }
 }
示例#19
0
 public function setUp()
 {
     if ($GLOBALS['db']->dbType != 'mysql') {
         $this->markTestSkipped('Only applies to MySQL');
     }
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     $id = create_guid();
     $sql = "INSERT INTO meetings (id, date_start, duration_hours, duration_minutes, date_end, deleted) VALUES('{$id}', '2010-10-11 23:45:00', 0, 30, '2010-10-12', 0)";
     $GLOBALS['db']->query($sql);
     $this->_meetingId = $id;
 }
 public function Insert_eventhits($eventid, $userid, $action, $useraction, $location, $locationx, $locationy, $clicktime)
 {
     $egood = $ebad = 0;
     if ($action == 0) {
         $ebad = 1;
     } else {
         $egood = 1;
     }
     $actiontime = date('Y-m-d H:i:s', time());
     $sqlquery = "SELECT * FROM eventhits where eventid='{$eventid}' and userid='{$userid}'";
     $resultquery = $this->conn->query($sqlquery);
     if ($resultquery->num_rows > 0) {
         while ($row = $resultquery->fetch_assoc()) {
             //返回键值对数组
             $user = new EventHit();
             $user->actiontime = $row["actiontime"];
             $time = ceil((strtotime($actiontime) - strtotime($user->actiontime)) / 3600);
             $file = 'F:\\wampserver\\setup\\wamp\\www\\manager_eventhit.txt';
             $time1 = "相差时间为" . $time . "\n";
             file_put_contents($file, $time1, FILE_APPEND);
             if ($time < 24) {
                 $user->kind = "time";
                 $json = json_encode($user);
                 echo $json;
                 return;
             }
         }
     }
     $eventhitid = create_guid();
     $logid = create_guid();
     $this->conn->autocommit(false);
     $this->sql1 = "INSERT INTO eventhits (eventhitid,eventid,userid,action,actiontime)\n           VALUES ('{$eventhitid}','{$eventid}','{$userid}','{$action}','{$actiontime}')";
     $this->sql2 = "UPDATE events SET good=good+'{$egood}',bad=bad-'{$ebad}'\n        WHERE eventid='{$eventid}'";
     $this->sql3 = "INSERT INTO logs (logid, userid,actiontype,useraction,actiontime,location,locationx,locationy)\n           VALUES ('{$logid}','{$userid}','点赞/鄙视','{$useraction}','{$actiontime}','{$location}','{$locationx}','{$locationy}')";
     if ($this->conn->query($this->sql1) && $this->conn->query($this->sql2) && $this->conn->query($this->sql3)) {
         $this->conn->commit();
         $user = new EventHit();
         $user->eventhitid = $eventhitid;
         $user->userid = $userid;
         $user->eventid = $eventid;
         $user->action = $action;
         $user->actiontime = $actiontime;
         $user->kind = "OK";
         $json = json_encode($user);
         echo $json;
     } else {
         $this->conn->rollback();
         $user = new EventHit();
         $user->kind = "NO";
         $json = json_encode($user);
         echo "{$json}";
     }
     $this->conn->close();
 }
示例#21
0
 /**
  * @param SugarBean $bean
  * @return string uploaded file name
  */
 public function uploadTemplate(&$bean)
 {
     global $mod_strings;
     $GLOBALS['log']->debug("Reports_Merge_Utils->uploadTemplate");
     //we need to manually set the id if it is not already set
     //so that we can name the file appropriately
     if (empty($bean->id)) {
         $bean->id = create_guid();
         $bean->new_with_id = true;
     }
     $field_name = 'filename';
     if (!empty($_FILES[$field_name]['name'])) {
         global $sugar_config;
         //if a previous file has been uploaded then remove it now
         $path_parts = pathinfo($_FILES[$field_name]['name']);
         if (!Reports_Utils::check_extension_template($path_parts['extension'])) {
             sugar_die('ERROR: ' . $mod_strings['ERR_UPLOADED_FILE_EXTENSION_NOT_SUPPORT']);
         }
         if (!empty($_REQUEST['old_' . $field_name])) {
             // create a non UTF-8 name encoding
             // 176 + 36 char guid = windows' maximum filename length
             $old_file_name = $_REQUEST['old_' . $field_name];
             $end = strlen($old_file_name) > 176 ? 176 : strlen($old_file_name);
             $stored_file_name = substr($old_file_name, 0, $end);
             $old_photo = $sugar_config['upload_dir'] . $bean->id . '_' . $old_file_name;
             $GLOBALS['log']->debug("Reports_Merge_Utils->uploadTemplate: Deleting old template: " . $old_photo);
             unlink($old_photo);
         }
         $file_name = $bean->id . '_' . $_FILES[$field_name]['name'];
         //save the file name to the database
         $bean->{$field_name} = $_FILES[$field_name]['name'];
         if (!is_uploaded_file($_FILES[$field_name]['tmp_name'])) {
             sugar_die("ERROR: {$mod_strings['ERR_NOT_UPLOAD']}");
             //return false;
         } elseif ($_FILES[$this->field_name]['size'] > $sugar_config['upload_maxsize']) {
             sugar_die("ERROR: {$mod_strings['ERR_MAX_SIZE_UPLOAD_FILE']}: {$sugar_config['upload_maxsize']}");
         }
         // create a non UTF-8 name encoding
         // 176 + 36 char guid = windows' maximum filename length
         $end = strlen($file_name) > 176 ? 176 : strlen($file_name);
         $stored_file_name = substr($file_name, 0, $end);
         $destination = $sugar_config['upload_dir'] . $stored_file_name;
         if (!is_writable($sugar_config['upload_dir'])) {
             sugar_die("ERROR: {$mod_strings['ERR_CANNT_WRITE_DIR']}: {$sugar_config['upload_dir']} for uploads");
         }
         //$destination = clean_path($this->get_upload_path($bean_id));
         if (!move_uploaded_file($_FILES[$field_name]['tmp_name'], $destination)) {
             sugar_die("ERROR: {$mod_strings['ERR_CANNT_MOVE']} {$destination}. {$mod_strings['ERR_NEED_WRITABLE_DIR']}");
         }
         return $bean->{$field_name};
     }
 }
示例#22
0
    function save_schedule($id, $user_id, $report_id, $date_start, $interval, $active, $schedule_type)
    {
        global $timedate;
        $origDateStart = $date_start;
        $date_modified = $timedate->nowDb();
        if (strlen(trim($origDateStart)) == 0) {
            $date_start_str = 'NULL';
        } else {
            $date_start_str = $this->db->quoted($origDateStart);
        }
        if (empty($id)) {
            $id = create_guid();
            if (empty($date_start)) {
                $date_start = $timedate->nowDb();
            }
            $next_run_date = $this->getNextRunDate($date_start, 0);
            $query = <<<QUERY
INSERT INTO {$this->table_name} (
    id, user_id, report_id, date_start, next_run, time_interval, active, date_modified, schedule_type
)
VALUES (
    {$this->db->quoted($id)},
    {$this->db->quoted($user_id)},
    {$this->db->quoted($report_id)},
    {$date_start_str},
    {$this->db->quoted($next_run_date)},
    {$this->db->quoted($interval)},
    {$this->db->quoted($active)},
    {$this->db->quoted($date_modified)},
    {$this->db->quoted($schedule_type)}
)
QUERY;
        } else {
            $query = <<<QUERY
UPDATE
    {$this->table_name}
SET
    time_interval = {$this->db->quoted($interval)},
    date_start = {$date_start_str},
    active = {$this->db->quoted($active)},
    date_modified = {$this->db->quoted($date_modified)},
    schedule_type = {$this->db->quoted($schedule_type)}
QUERY;
            if (!empty($date_start) && $active) {
                $next_run_date = $this->getNextRunDate($date_start, $interval);
                $query .= ", next_run = " . $this->db->quoted($next_run_date);
            }
            $query .= " WHERE id = " . $this->db->quoted($id);
        }
        $this->db->query($query, true, "error saving schedule");
        return $id;
    }
示例#23
0
 function updateRelate(&$bean, $event, $arguments)
 {
     global $db;
     // Cau hinh thong so cho cac module co quan he
     // table: bang quan he
     // parentID: Cot trong ban quan he luu tru ID cua module duoc Select
     // recordID: Cot trong ban quan he luu tru ID cua module chua nut Select
     $relateModuleConfig = array('Accounts' => array('table' => 'accounts_quotes_c', 'parentIDKey' => 'accounts_qd96cccounts_ida', 'recordIDKey' => 'accounts_q5e58squotes_idb'), 'FITs' => array('table' => 'fits_quotes_c', 'parentIDKey' => 'fits_quotedcbetesfits_ida', 'recordIDKey' => 'fits_quote8d28squotes_idb'));
     // Lay ra cac gia tri cho quan he moi
     $recordID = $bean->id;
     $relateModule = $bean->parent_type;
     $parentID = $bean->parent_id;
     $relateTable = $relateModuleConfig[$relateModule]['table'];
     $parentIDKey = $relateModuleConfig[$relateModule]['parentIDKey'];
     $recordIDkey = $relateModuleConfig[$relateModule]['recordIDKey'];
     // Lay ra cac gia tri cua quan he cu
     $oldRelateModule = $bean->fetched_row['parent_type'];
     $oldParentID = $bean->fetched_row['parent_id'];
     $oldRelateTable = $relateModuleConfig[$oldRelateModule]['table'];
     $oldParentIDKey = $relateModuleConfig[$oldRelateModule]['parentIDKey'];
     $oldRecordIDkey = $relateModuleConfig[$oldRelateModule]['recordIDKey'];
     // Xu ly
     if ($parentID != $oldParentID && $oldParentID != '') {
         // Khi co su thay doi
         $id = create_guid();
         // Tao ID cho relate record theo chuan cua Sugar
         // Tao quan he moi
         if ($parentID != '') {
             // Parent ID ton tai thi moi tao quan he
             $sql_set_relate = ' INSERT INTO ' . $relateTable . ' (id, ' . $recordIDkey . ', ' . $parentIDKey . ', date_modified, deleted)
                                     VALUES ("' . $id . '","' . $recordID . '","' . $parentID . '", NOW(), 0)';
             $db->query($sql_set_relate);
         }
         // Xoa quan he cu
         $sql_del_relate = ' UPDATE ' . $oldRelateTable . ' 
                                 SET deleted = 1 
                                 WHERE ' . $oldRecordIDkey . ' = "' . $recordID . '" AND ' . $oldParentIDKey . ' = "' . $oldParentID . '"';
         $db->query($sql_del_relate);
     }
     if ($oldParentID == '') {
         $id = create_guid();
         // Tao ID cho relate record theo chuan cua Sugar
         // Tao quan he moi
         if ($parentID != '') {
             // Parent ID ton tai thi moi tao quan he
             $sql_set_relate = ' INSERT INTO ' . $relateTable . ' (id, ' . $recordIDkey . ', ' . $parentIDKey . ', date_modified, deleted)
                                     VALUES ("' . $id . '","' . $recordID . '","' . $parentID . '", NOW(), 0)';
             $db->query($sql_set_relate);
         }
     }
 }
示例#24
0
 public function setUp()
 {
     global $current_user;
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $this->normalUser = SugarTestUserUtilities::createAnonymousUser(false);
     $this->normalUser->id = create_guid();
     $this->normalUser->user_type = 'RegularUser';
     $this->groupUser = SugarTestUserUtilities::createAnonymousUser(false);
     $this->groupUser->id = create_guid();
     $this->groupUser->is_group = 1;
     $this->groupUser->user_type = 'GROUP';
     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
 }
 /**
  * Process all the results and insert them back into the db
  *
  * @param resource $results
  */
 protected function insertRows($results)
 {
     $insertSQL = "INSERT INTO forecast_worksheets (\n                        id,\n                        name,\n                        parent_id,\n                        parent_type,\n                        draft) values";
     /* @var $fw ForecastWorksheets */
     $fw = BeanFactory::getBean('ForecastWorksheets');
     while ($row = $this->db->fetchByAssoc($results)) {
         $row['id'] = create_guid();
         foreach ($row as $key => $value) {
             $row[$key] = $this->db->massageValue($value, $fw->getFieldDefinition($key));
         }
         $q = $insertSQL . ' (' . join(',', $row) . ');';
         $this->db->query($q);
     }
 }
示例#26
0
 function addDashlet()
 {
     if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php')) {
         require_once 'include/Dashlets/DashletCacheBuilder.php';
         $dc = new DashletCacheBuilder();
         $dc->buildCache();
     }
     require_once $GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php';
     global $current_user;
     if (isset($_REQUEST['id'])) {
         $pages = $current_user->getPreference('pages', $this->type);
         $dashlets = $current_user->getPreference('dashlets', $this->type);
         $guid = create_guid();
         $options = array();
         if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'web') {
             $dashlet_module = 'Home';
             $options['url'] = $_REQUEST['type_module'];
             $fp = @fopen($options['url'], 'r');
             if ($fp) {
                 $page = fread($fp, 8192);
                 $matches = array();
                 preg_match("/<title>(.*)<\\/title>/i", $page, $matches);
                 if (isset($matches[1])) {
                     $options['title'] = str_replace('<![CDATA[', '', str_replace(']]>', '', $matches[1]));
                 }
                 fclose($fp);
             }
         } elseif (isset($_REQUEST['type_module'])) {
             $dashlet_module = $_REQUEST['type_module'];
         } elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
             $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
         } else {
             $dashlet_module = 'Home';
         }
         $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'], 'module' => $dashlet_module, 'options' => $options, 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
         // add to beginning of the array
         array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
         //check to see whether the preference is too large to store
         if ($current_user->isPreferenceSizeTooLarge($this->type)) {
             //user preference is too large, do not attempt to store.  echo error string and return.  This will be processed by mySugar.js
             echo 'userpref_error';
             return false;
         }
         //store preference and echo guid
         $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
         echo $guid;
     } else {
         echo 'ofdaops';
     }
 }
示例#27
0
 /**
  * Submit a new job to the queue
  *
  * @param SchedulersJob $job Job object
  *
  * @return string            Job ID
  */
 public function submitJob($job)
 {
     $job->id = create_guid();
     $job->new_with_id = true;
     $job->status = SchedulersJob::JOB_STATUS_QUEUED;
     $job->resolution = SchedulersJob::JOB_PENDING;
     if (empty($job->execute_time)) {
         $job->execute_time = $GLOBALS['timedate']->nowDb();
     }
     if (empty($job->assigned_user_id)) {
         $job->assigned_user_id = $GLOBALS['current_user']->id;
     }
     $job->save();
     return $job->id;
 }
示例#28
0
 public function setUp()
 {
     if ($GLOBALS['db']->dbType != 'mysql') {
         $this->markTestSkipped('Only applies to MySQL');
     }
     SugarTestHelper::setUp('beanFiles');
     SugarTestHelper::setUp('beanList');
     SugarTestHelper::setUp('current_user');
     SugarTestHelper::setUp('app_strings');
     SugarTestHelper::setUp('app_list_strings');
     $id = create_guid();
     $sql = "INSERT INTO meetings (id, date_start, duration_hours, duration_minutes, date_end, deleted) VALUES('{$id}', '2010-10-11 23:45:00', 0, 30, '2010-10-12', 0)";
     $GLOBALS['db']->query($sql);
     $this->_meetingId = $id;
 }
示例#29
0
 public function setUp()
 {
     global $currentModule;
     $this->call_id = create_guid();
     $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     //create a contact
     $this->contact = new Contact();
     $this->contact->first_name = 'Joe UT ';
     $this->contact->last_name = 'Smith UT 50438';
     $this->contact->disable_custom_fields = true;
     $this->contact->save();
     //create array to output as import file using the new contact as the related parent
     $this->fileArr = array(0 => "\"{$this->call_id}\",\"Call for Unit Test 50438\",\"Planned\", \"{$this->contact->module_dir}\",\"{$this->contact->id}\"");
 }
 /**
  * Process all the results and insert them back into the db
  *
  * @param resource $results
  */
 protected function insertRows($results)
 {
     $insertSQL = 'INSERT INTO forecast_worksheets ';
     /* @var $fw ForecastWorksheet */
     $fw = BeanFactory::getBean('ForecastWorksheets');
     while ($row = $this->db->fetchByAssoc($results)) {
         $row['id'] = create_guid();
         foreach ($row as $key => $value) {
             $fieldDefs = $fw->getFieldDefinition($key);
             $convertedValue = $this->db->fromConvert($value, $this->db->getFieldType($fieldDefs));
             $row[$key] = $this->db->massageValue($convertedValue, $fieldDefs);
         }
         $this->db->query($insertSQL . '(' . join(',', array_keys($row)) . ') VALUES (' . join(',', $row) . ');');
     }
 }