Example #1
0
 /**
  * Serves the Soap Request
  * @return
  */
 public function serve()
 {
     ob_clean();
     global $HTTP_RAW_POST_DATA;
     $GLOBALS['log']->debug("I am here1 " . $HTTP_RAW_POST_DATA);
     $qs = '';
     if (isset($_SERVER['QUERY_STRING'])) {
         $qs = $_SERVER['QUERY_STRING'];
     } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
         $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
     } else {
         $qs = '';
     }
     if (stristr($qs, 'wsdl') || $HTTP_RAW_POST_DATA == '') {
         $wsdlCacheFile = $this->getWSDLPath(false);
         if (stristr($qs, 'wsdl')) {
             $contents = @sugar_file_get_contents($wsdlCacheFile);
             if ($contents !== false) {
                 header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
                 print $contents;
             }
             // if
         } else {
             $this->nusoap_server->service($HTTP_RAW_POST_DATA);
         }
         // else
     } else {
         $this->server->handle();
     }
     ob_end_flush();
     flush();
 }
Example #2
0
 * Description:
 ********************************************************************************/
$default_versions = array();
$new_db = DBManagerFactory::getInstance();
$db_version = '2.5.1';
$dirName = 'custom/include/language';
if (is_dir($dirName)) {
    $d = dir($dirName);
    while ($entry = $d->read()) {
        if ($entry != "." && $entry != "..") {
            // echo $dirName."/".$entry;
            if (is_file($dirName . "/" . $entry) && substr($entry, -9) == '.lang.php') {
                $custom_lang_file = $dirName . "/" . $entry;
                if (is_readable($custom_lang_file)) {
                    $pattern = '/\\$app_list_strings[\\ ]*=[\\ ]*array/';
                    $subject = @sugar_file_get_contents($custom_lang_file);
                    $matches = preg_match($pattern, $subject);
                    if ($matches > 0) {
                        $db_version = '0';
                    }
                }
            }
        }
    }
}
//$default_versions[] = array('name'=>'Custom Labels', 'db_version' =>'3.0', 'file_version'=>'3.0');
$default_versions[] = array('name' => 'Chart Data Cache', 'db_version' => '3.5.1', 'file_version' => '3.5.1');
$default_versions[] = array('name' => 'htaccess', 'db_version' => '3.5.1', 'file_version' => '3.5.1');
//$default_versions[] = array('name'=>'DST Fix', 'db_version' =>'3.5.1b', 'file_version'=>'3.5.1b');
$default_versions[] = array('name' => 'Rebuild Relationships', 'db_version' => '4.0.0', 'file_version' => '4.0.0');
$default_versions[] = array('name' => 'Rebuild Extensions', 'db_version' => '4.0.0', 'file_version' => '4.0.0');
function disc_client_get_zip($soapclient, $session, $verbose = false, $attempts = 0, $force_md5_sync = false)
{
    $max_attempts = 3;
    global $sugar_config, $timedate;
    // files might be big
    ini_set("memory_limit", "-1");
    set_time_limit(3600);
    ini_set('default_socket_timeout', 3600);
    $return_str = "";
    //1) rather than using md5, we will use the date_modified
    if (file_exists('modules/Sync/file_config.php') && $force_md5_sync != true) {
        require_once 'modules/Sync/file_config.php';
        global $file_sync_info;
        if (!isset($file_sync_info['last_local_sync']) && !isset($file_sync_info['last_server_sync'])) {
            $last_server_sync = $last_local_sync = $timedate->nowDb();
            $is_first_sync = true;
        } else {
            $last_local_sync = $file_sync_info['last_local_sync'];
            $last_server_sync = $file_sync_info['last_server_sync'];
            $is_first_sync = false;
        }
    } else {
        $last_server_sync = $last_local_sync = $timedate->nowDb();
        $is_first_sync = true;
    }
    $tempdir = create_cache_directory("disc_client");
    $temp_file = tempnam($tempdir, "sug");
    $file_list = array();
    if (!$is_first_sync) {
        $all_src_files = findAllTouchedFiles(".", array(), $last_local_sync);
        foreach ($all_src_files as $src_file) {
            $file_list[$src_file] = $src_file;
        }
    } else {
        $all_src_files = findAllFiles(".", array());
        require "install/data/disc_client.php";
        foreach ($all_src_files as $src_file) {
            foreach ($disc_client_ignore as $ignore_pattern) {
                if (!preg_match("#" . $ignore_pattern . "#", $src_file)) {
                    $md5 = md5_file($src_file);
                    $file_list[$src_file] = $md5;
                }
            }
        }
    }
    //2) save the list of md5 files to file system
    if (!write_array_to_file("client_file_list", $file_list, $temp_file)) {
        echo "Could not save file.";
    }
    // read file
    $contents = sugar_file_get_contents($temp_file);
    $md5 = md5($contents);
    // encode data
    $data = base64_encode($contents);
    $md5file = array('filename' => $temp_file, 'md5' => $md5, 'data' => $data, 'error' => null);
    $result = $soapclient->call('get_encoded_zip_file', array('session' => $session, 'md5file' => $md5file, 'last_sync' => $last_server_sync, 'is_md5_sync' => $is_first_sync));
    //3) at this point we could have the zip file
    $zip_file = tempnam($tempdir, "zip") . '.zip';
    if (isset($result['result']) && !empty($result['result'])) {
        $fh = sugar_fopen($zip_file, 'w');
        fwrite($fh, base64_decode($result['result']));
        fclose($fh);
        unzip($zip_file, ".", true);
    }
    if (file_exists($zip_file)) {
        unlink($zip_file);
    }
    $file_sync_info['last_local_sync'] = $timedate->nowDb();
    $server_time = $soapclient->call('get_gmt_time', array());
    $file_sync_info['last_server_sync'] = $server_time;
    $file_sync_info['is_first_sync'] = $is_first_sync;
    write_array_to_file('file_sync_info', $file_sync_info, 'modules/Sync/file_config.php');
    echo "File sync complete.";
}
Example #4
0
/**
 * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
 * properly authenticated user to download a document that they have proper rights to download.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $id      -- ID of the document revision to obtain
 * @return return_document_revision - this is a complex type as defined in SoapTypes.php
 */
function get_document_revision($session, $id)
{
    global $sugar_config;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $dr = new DocumentRevision();
    $dr->retrieve($id);
    if (!empty($dr->filename)) {
        $filename = "upload://{$dr->id}";
        $contents = base64_encode(sugar_file_get_contents($filename));
        return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error' => $error->get_soap_array());
    } else {
        $error->set_error('no_records');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
}
Example #5
0
function doSearch($index, $queryString, $start = 0, $amount = 20)
{
    global $current_user;
    $cachePath = 'cache/modules/AOD_Index/QueryCache/' . md5($queryString);
    if (is_file($cachePath)) {
        $mTime = getCorrectMTime($cachePath);
        if ($mTime > time() - 5 * 60) {
            $hits = unserialize(sugar_file_get_contents($cachePath));
        }
    }
    if (!isset($hits)) {
        $tmphits = $index->find($queryString);
        $hits = array();
        foreach ($tmphits as $hit) {
            $bean = BeanFactory::getBean($hit->record_module, $hit->record_id);
            if (empty($bean)) {
                continue;
            }
            if ($bean->bean_implements('ACL') && !is_admin($current_user)) {
                //Annoyingly can't use the following as it always passes true for is_owner checks on list
                //$bean->ACLAccess('list');
                $in_group = SecurityGroup::groupHasAccess($bean->module_dir, $bean->id, 'list');
                $is_owner = $bean->isOwner($current_user->id);
                $access = ACLController::checkAccess($bean->module_dir, 'list', $is_owner, 'module', $in_group);
                if (!$access) {
                    continue;
                }
            }
            $newHit = new stdClass();
            $newHit->record_module = $hit->record_module;
            $newHit->record_id = $hit->record_id;
            $newHit->score = $hit->score;
            $newHit->label = getModuleLabel($bean->module_name);
            $newHit->name = $bean->get_summary_text();
            $newHit->summary = getRecordSummary($bean);
            $newHit->date_entered = $bean->date_entered;
            $newHit->date_modified = $bean->date_modified;
            $hits[] = $newHit;
        }
        //Cache results so pagination is nice and snappy.
        cacheQuery($queryString, $hits);
    }
    $total = count($hits);
    $hits = array_slice($hits, $start, $amount);
    $res = array('total' => $total, 'hits' => $hits);
    return $res;
}
function get_encoded_portal_zip_file($session, $md5file, $last_sync, $is_md5_sync = 1)
{
    // files might be big
    global $sugar_config;
    ini_set("memory_limit", "-1");
    $md5 = "";
    $data = "";
    $error = new SoapError();
    $the_error = "";
    if (!validate_authenticated($session)) {
        $the_error = "Invalid session";
    }
    require "install/data/disc_client.php";
    $tempdir_parent = create_cache_directory("disc_client");
    $temp_dir = tempnam($tempdir_parent, "sug");
    sugar_mkdir($temp_dir, 0775);
    $temp_file = tempnam($temp_dir, "sug");
    write_encoded_file($md5file, $temp_dir, $temp_file);
    $ignore = false;
    //generate md5 files on server
    require_once $temp_file;
    $server_files = array();
    // used later for removing unneeded local files
    $zip_file = tempnam(tempdir_parent, $session);
    $root_files = array();
    $custom_files = array();
    $file_list = array();
    if (!$is_md5_sync) {
        if (is_dir("portal")) {
            $root_files = findAllTouchedFiles("portal", array(), $last_sync);
        }
        if (is_dir("custom/portal")) {
            $custom_files = findAllTouchedFiles("custom/portal", array(), $last_sync);
        }
        $all_src_files = array_merge($root_files, $custom_files);
        foreach ($all_src_files as $src_file) {
            $ignore = false;
            foreach ($disc_client_ignore as $ignore_pattern) {
                if (preg_match("#" . $ignore_pattern . "#", $src_file)) {
                    $ignore = true;
                }
            }
            if (!$ignore) {
                //we have to strip off portal or custom/portal before the src file to look it up
                $key = str_replace('custom/portal/', '', $src_file);
                $key = str_replace('portal/', '', $key);
                if ($client_file_list != null && isset($client_file_list[$key])) {
                    //we have found a file out of sync
                    $file_list[] = $src_file;
                    //since we have processed this element of the client
                    //list of files, remove it from the list
                    unset($client_file_list[$key]);
                } else {
                    //this file does not exist on the client side
                    $file_list[] = $src_file;
                }
            }
        }
    } else {
        if (is_dir("portal")) {
            $root_files = findAllFiles("portal", array());
        }
        if (is_dir("custom/portal")) {
            $custom_files = findAllFiles("custom/portal", array());
        }
        $all_src_files = array_merge($root_files, $custom_files);
        foreach ($all_src_files as $src_file) {
            $ignore = false;
            foreach ($disc_client_ignore as $ignore_pattern) {
                if (preg_match("#" . $ignore_pattern . "#", $src_file)) {
                    $ignore = true;
                }
            }
            if (!$ignore) {
                $value = md5_file($src_file);
                //we have to strip off portal or custom/portal before the src file to look it up
                $key = str_replace('custom/portal/', '', $src_file);
                $key = str_replace('portal/', '', $key);
                if ($client_file_list != null && isset($client_file_list[$key])) {
                    if ($value != $client_file_list[$key]) {
                        //we have found a file out of sync
                        $file_list[] = $src_file;
                        //since we have processed this element of the client
                        //list of files, remove it from the list
                    }
                    unset($client_file_list[$key]);
                } else {
                    //this file does not exist on the client side
                    $file_list[] = $src_file;
                }
            }
        }
    }
    zip_files_list($zip_file, $file_list, '|.*portal/|');
    $contents = sugar_file_get_contents($zip_file);
    // encode data
    $data = base64_encode($contents);
    unlink($zip_file);
    return array('result' => $data, 'error' => $error->get_soap_array());
}
 /**
  * Shows a list of files that might need manual updating
  *
  * @param string $searchString
  * @param string $oldKey
  * @return bool
  */
 private function updateFiles($newKey, $oldKey)
 {
     $matches = array();
     if (empty($newKey) || in_array($oldKey, $this->customListNames)) {
         return false;
     }
     $searchString1 = "'" . $oldKey . "'";
     $searchString2 = '"' . $oldKey . '"';
     foreach ($this->customOtherFileList as $fileName) {
         $text = sugar_file_get_contents($fileName);
         if (strpos($text, $searchString1) !== FALSE || strpos($text, $searchString2) !== FALSE) {
             $oldText = array("=> '{$oldKey}'", "=> \"{$oldKey}\"", "=>'{$oldKey}'", "=>\"{$oldKey}\"", "= '{$oldKey}'", "= \"{$oldKey}\"", "='{$oldKey}'", "=\"{$oldKey}\"");
             $newText = array("=> '{$newKey}'", "=> \"{$newKey}\"", "=>'{$newKey}'", "=>\"{$newKey}\"", "= '{$newKey}'", "= \"{$newKey}\"", "='{$newKey}'", "=\"{$newKey}\"");
             $text = str_replace($oldText, $newText, $text);
             if (strpos($text, $searchString1) !== FALSE) {
                 $matches[$fileName] = true;
                 $this->customListNames[] = $oldKey;
             } else {
                 $this->modifiedFiles[$fileName] = $this->truncateFileName($fileName);
                 $this->backupFile($fileName);
                 sugar_file_put_contents($fileName, $text, LOCK_EX);
             }
         }
     }
     if (!empty($matches)) {
         $this->logThis("------------------------------------------------------------", self::SEV_MEDIUM);
         $this->logThis("These files MAY need to be updated to reflect the new key (New '{$newKey}' vs. old '{$oldKey}')", self::SEV_MEDIUM);
         $this->logThis("-------------------------------------------------------------", self::SEV_MEDIUM);
         foreach ($matches as $fileName => $flag) {
             $this->manualFixFiles[$fileName] = $this->truncateFileName($fileName);
             $this->logThis($this->truncateFileName($fileName), self::SEV_MEDIUM);
         }
         $this->logThis("-------------------------------------------------------------", self::SEV_MEDIUM);
     }
 }
 /**
  * A Static method used to obtain the div for the license
  *
  * @param String license_file - the path to the license file
  * @param String form_action - the form action when accepting the license file
  * @param String next_step - the value for the next step in the installation process
  * @param String zipFile - a string representing the path to the zip file
  * @param String type - module/patch....
  * @param String manifest - the path to the manifest file
  * @param String modify_field - the field to update when the radio button is changed
  * @return String - a form used to display the license
  */
 function getLicenseDisplay($license_file, $form_action, $next_step, $zipFile, $type, $manifest, $modify_field)
 {
     global $current_language;
     $mod_strings = return_module_language($current_language, "Administration");
     $contents = sugar_file_get_contents($license_file);
     $div_id = urlencode($zipFile);
     $display = "<form name='delete{$zipFile}' action='{$form_action}' method='POST'>";
     $display .= "<input type='hidden' name='current_step' value='{$next_step}'>";
     $display .= "<input type='hidden' name='languagePackAction' value='{$type}'>";
     $display .= "<input type='hidden' name='manifest' value='\".urlencode({$manifest}).\"'>";
     $display .= "<input type='hidden' name='zipFile' value='\".urlencode({$zipFile}).\"'>";
     $display .= "<table><tr>";
     $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
     $display .= "<b><font color='red' >{$mod_strings['LBL_MODULE_LICENSE']}</font></b>";
     $display .= "</td>";
     $display .= "<td>";
     $display .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleLowerDiv('span_animate_div_{$div_id}', 'span_license_div_{$div_id}', 350, 0);\"><span id='span_animate_div_{$div_id}'<img src='" . SugarThemeRegistry::current()->getImageURL('advanced_search.gif') . "' width='8' height='8' alt='Advanced' border='0'>&nbsp;Expand</span></a></slot></td>";
     $display .= "</td>";
     $display .= "</tr>";
     $display .= "</table>";
     $display .= "<div id='span_license_div_{$div_id}' style=\"display: none;\">";
     $display .= "<table>";
     $display .= "<tr>";
     $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
     $display .= "<textarea cols=\"100\" rows=\"8\">{$contents}</textarea>";
     $display .= "</td>";
     $display .= "</tr>";
     $display .= "<tr>";
     $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
     $display .= "<input type='radio' id='radio_license_agreement_accept' name='radio_license_agreement' value='accept' onClick=\"document.getElementById('{$modify_field}').value = 'yes';\">{$mod_strings['LBL_ACCEPT']}&nbsp;";
     $display .= "<input type='radio' id='radio_license_agreement_reject' name='radio_license_agreement' value='reject' checked onClick=\"document.getElementById('{$modify_field}').value = 'no';\">{$mod_strings['LBL_DENY']}";
     $display .= "</td>";
     $display .= "</tr>";
     $display .= "</table>";
     $display .= "</div>";
     $display .= "</form>";
     return $display;
 }
                echo $mod_strings['LBL_UW_PATCH_READY'];
            }
        }
    }
} else {
    echo $mod_strings['LBL_UW_PATCH_READY2'];
    echo '<input type="checkbox" onclick="toggle_these(0, ' . count($new_studio_mod_files) . ', this)"> ' . $mod_strings['LBL_UW_CHECK_ALL'];
    foreach ($new_studio_mod_files as $the_file) {
        $new_file = clean_path("{$zip_to_dir}/{$the_file}");
        print "<li><input id=\"copy_{$count}\" name=\"copy_{$count}\" type=\"checkbox\" value=\"" . $the_file . "\"> " . $new_file . "</li>";
        $count++;
    }
}
echo '<br>';
if ($require_license) {
    $contents = sugar_file_get_contents($license_file);
    $readme_contents = '';
    if ($found_readme) {
        if (file_exists($readme_file) && filesize($readme_file) > 0) {
            $readme_contents = file_get_contents($readme_file);
        } elseif (!empty($manifest['readme'])) {
            $readme_contents = $manifest['readme'];
        }
    }
    $license_final = <<<eoq2
\t<table width='100%'>
\t<tr>
\t<td colspan="3"><ul class="tablist">
\t<li id="license_li" class="active"><a id="license_link"  class="current" href="javascript:selectTabCSS('license');">{$mod_strings['LBL_LICENSE']}</a></li>
\t<li class="active" id="readme_li"><a id="readme_link" href="javascript:selectTabCSS('readme');">{$mod_strings['LBL_README']}</a></li>
\t</ul></td>
Example #10
0
/**
 * @deprecated
 * @todo this function is only used by one function ( run_upgrade_wizard_sql() ), which isn't
 *       used either; trying kill this off
 */
function run_sql_file($filename)
{
    if (!is_file($filename)) {
        print "Could not find file: {$filename} <br>";
        return false;
    }
    $contents = sugar_file_get_contents($filename);
    $lastsemi = strrpos($contents, ';');
    $contents = substr($contents, 0, $lastsemi);
    $queries = explode(';', $contents);
    $db = DBManagerFactory::getInstance();
    foreach ($queries as $query) {
        if (!empty($query)) {
            if ($db->dbType == 'oci8') {
            } else {
                $db->query($query . ';', true, "An error has occured while running.<br>");
            }
        }
    }
    return true;
}
 /**
  * Load a configuration file manually.
  *
  * @param string $file_name file name to load
  * @param boolean $prepend_path whether current config path should be
  *                              prepended to the filename
  */
 function load_file($file_name, $prepend_path = true)
 {
     if ($prepend_path && $this->_config_path != "") {
         $config_file = $this->_config_path . $file_name;
     } else {
         $config_file = $file_name;
     }
     ini_set('track_errors', true);
     $contents = @sugar_file_get_contents($config_file);
     if ($contents === false) {
         $this->_trigger_error_msg("Could not open config file '{$config_file}'");
         return false;
     }
     $this->_config_data[$config_file] = $this->parse_contents($contents);
     return true;
 }
Example #12
0
/**
 * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
 * properly authenticated user to download a document that they have proper rights to download.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $id      -- ID of the document revision to obtain
 * @return return_document_revision - this is a complex type as defined in SoapTypes.php
 */
function get_document_revision($session, $id)
{
    global $sugar_config;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $dr = new DocumentRevision();
    $dr->retrieve($id);
    if (!empty($dr->filename)) {
        $filename = $sugar_config['upload_dir'] . "/" . $dr->id;
        $contents = base64_encode(sugar_file_get_contents($filename));
        //        $fh = sugar_fopen($sugar_config['upload_dir']."/rogerrsmith.doc", 'w');
        //        fwrite($fh, base64_decode($contents));
        return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error' => $error->get_soap_array());
    } else {
        $error->set_error('no_records');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
}
function debugPdfCreation($filename)
{
    $pdfLatexDir = dirname($filename);
    $pdfLatexArgs = '-interaction=nonstopmode -output-directory=' . $pdfLatexDir . ' ' . $filename . ' 2>&1';
    $pdfTestArgs = '-version';
    $returnTestValue = null;
    $consoleOutput = array();
    //try to use value from config file first
    $defaultPath = PDFLATEX;
    $found = '';
    $addString = '';
    $filenameWithoutExtension = str_replace("\\", "/", $pdfLatexDir . DIRECTORY_SEPARATOR . basename($filename, '.tmp'));
    $pdfFilename = $filenameWithoutExtension . '.pdf';
    $returnTestValue = execute(PDFLATEX, $pdfTestArgs, $consoleOutput);
    if ($returnTestValue === 0) {
        $addString = "\npdflatex file is found at location entered in config file.\n";
        if (!empty($consoleOutput)) {
            $addString .= "pdflatex -version output: \n\r" . implode("\n", $consoleOutput);
        } else {
            $addString .= "\npdflatex -version output: null";
        }
    } else {
        $addString = "\npdflatex executable is not found at default location, trying to find it at some other locations\n";
        $defaultPath = DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'pdflatex';
        $defaultTexName = 'pdflatex';
        if (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') {
            $defaultTexName = 'pdflatex.exe';
            $defaultPath = 'C:/Program Files/MiKTeX 2.9/miktex/bin/pdflatex.exe';
        } elseif (strtoupper(substr(php_uname('s'), 0, 3)) === 'DAR') {
            $defaultPath = '/usr/texbin/pdflatex';
        }
        if (file_exists($defaultPath)) {
            //$addString .= "pdflatex file is found at location {$defaultPath} that is different to one in Your config file. Modify config file and re-run pdf creation\n";
            $found = $defaultPath;
        } else {
            //try more complicated search
            $apachePath = getenv('PATH');
            $addString .= "Trying paths in PATH variable: {$apachePath}\n";
            //$GLOBALS['log']->error('latexToPdf: $PATH variable is ' . getenv('PATH'));
            $paths = explode(PATH_SEPARATOR, $apachePath);
            foreach ($paths as $p) {
                $fullname = $p . DIRECTORY_SEPARATOR . $defaultTexName;
                $addString .= "Looking for pdflatex at: {$fullname}\n";
                //$GLOBALS['log']->error('latexToPdf: looking for pdflatex at ' . $fullname);
                if (is_file($fullname)) {
                    $found = $fullname;
                    break;
                }
            }
        }
        if ($found) {
            //check if we found correct file
            $defaultPath = $found;
            $addString .= "pdflatex file is found at location {$defaultPath} that is different to one in Your config file. Modify config file and re-run pdf creation\n";
            $consoleOutput = array();
            $returnTestValue = execute($defaultPath, $pdfTestArgs, $consoleOutput);
            if (!empty($consoleOutput) && $returnTestValue === 0) {
                $addString .= "pdflatex -version output: \n" . implode("\n", $consoleOutput);
            } else {
                $addString .= "npdflatex -version output: null.\nThere still is problem with running of pdflatex; check file permissions.\n";
                sugar_file_put_contents($filename, $addString, FILE_APPEND | LOCK_EX);
                //Rewrite old log file
                rename($filename, $filenameWithoutExtension . '.log');
                return $filenameWithoutExtension . '.log';
            }
        } else {
            $addString .= "Most likely You do not have pdflatex package installed\n";
            sugar_file_put_contents($filename, $addString, FILE_APPEND | LOCK_EX);
            //Rewrite old log file
            rename($filename, $filenameWithoutExtension . '.log');
            return $filenameWithoutExtension . '.log';
        }
    }
    if (CENTOS_PATCH) {
        putenv('HOME=/tmp/');
    }
    $consoleOutput = array();
    $returnValue = execute($defaultPath, $pdfLatexArgs, $consoleOutput);
    if (!empty($consoleOutput)) {
        $addString .= "\n\rBELOW IS CONSOLE OUTPUT OF PDFLATEX RUN:\n\r" . implode("\n", $consoleOutput);
    } else {
        $addString .= "\n\rConsole output is empty for some reason.";
    }
    if (file_exists($filenameWithoutExtension . '.log')) {
        $addString .= "\n\rBELOW IS LOG FILE OF PDFLATEX RUN: \n\r" . sugar_file_get_contents($filenameWithoutExtension . '.log');
    } else {
        $addString .= "\n\rLog file does not exists";
    }
    sugar_file_put_contents($filename, $addString, FILE_APPEND | LOCK_EX);
    //Rewrite old log file
    rename($filename, $filenameWithoutExtension . '.log');
    return $filenameWithoutExtension . '.log';
}
Example #14
0
 /**
  * Takes a prepared stmt index and the data to replace and creates the query and runs it.
  *
  * @param  int		$stmt       The index of the prepared statement from preparedTokens
  * @param  array    $data 		The array of data to replace the tokens with.
  * @return resource result set or false on error
  */
 public function executePreparedQuery($stmt, $data = array())
 {
     if (!empty($this->preparedTokens[$stmt])) {
         if (!is_array($data)) {
             $data = array($data);
         }
         $pTokens = $this->preparedTokens[$stmt];
         //ensure that the number of data elements matches the number of replacement tokens
         //we found in prepare().
         if (count($data) != $pTokens['tokenCount']) {
             //error the data count did not match the token count
             return false;
         }
         $query = '';
         $dataIndex = 0;
         $tokens = $pTokens['tokens'];
         foreach ($tokens as $val) {
             switch ($val) {
                 case '?':
                     $query .= $this->quote($data[$dataIndex++]);
                     break;
                 case '&':
                     $filename = $data[$dataIndex++];
                     $query .= sugar_file_get_contents($filename);
                     break;
                 case '!':
                     $query .= $data[$dataIndex++];
                     break;
                 default:
                     $query .= $val;
                     break;
             }
             //switch
         }
         //foreach
         return $this->query($query);
     } else {
         return false;
     }
 }
Example #15
0
 function cacheXTPL($file, $cache_file, $preview_file = false)
 {
     global $beanList;
     //now if we have a backup_file lets use that instead of the original
     if ($preview_file) {
         $file = $preview_file;
     }
     if (!isset($the_module)) {
         $the_module = $_SESSION['studio']['module'];
     }
     $files = StudioParser::getFiles($the_module);
     $xtpl = $files[$_SESSION['studio']['selectedFileId']]['php_file'];
     $originalFile = $files[$_SESSION['studio']['selectedFileId']]['template_file'];
     $type = StudioParser::getFileType($files[$_SESSION['studio']['selectedFileId']]['type']);
     $buffer = sugar_file_get_contents($xtpl);
     $cache_file = create_cache_directory('studio/' . $file);
     $xtpl_cache = create_cache_directory('studio/' . $xtpl);
     $module = $this->workingModule;
     $form_string = "require_once('modules/" . $module . "/Forms.php');";
     if ($type == 'edit' || $type == 'detail') {
         if (empty($_REQUEST['record'])) {
             $buffer = preg_replace('(\\$xtpl[\\ ]*=)', "\$focus->assign_display_fields('{$module}'); \$0", $buffer);
         } else {
             $buffer = preg_replace('(\\$xtpl[\\ ]*=)', "\$focus->retrieve('" . $_REQUEST['record'] . "');\n\$focus->assign_display_fields('{$module}');\n \$0", $buffer);
         }
     }
     $_REQUEST['query'] = true;
     if (substr_count($file, 'SearchForm') > 0) {
         $temp_xtpl = new XTemplate($file);
         if ($temp_xtpl->exists('advanced')) {
             global $current_language;
             $mods = return_module_language($current_language, 'DynamicLayout');
             $mod = BeanFactory::getBean($module);
             $this->populateRequestFromBuffer($file);
             $mod->assign_display_fields($module);
             $buffer = str_replace(array('echo $lv->display();', '$search_form->parse("advanced");', '$search_form->out("advanced");', '$search_form->parse("main");', '$search_form->out("main");'), '', $buffer);
             $buffer = str_replace('echo get_form_footer();', '$search_form->parse("main");' . "\n" . '$search_form->out("main");' . "\necho '<br><b>" . translate('LBL_ADVANCED', 'DynamicLayout') . "</b><br>';" . '$search_form->parse("advanced");' . "\n" . '$search_form->out("advanced");' . "\n \$sugar_config['list_max_entries_per_page'] = 1;", $buffer);
         }
     } else {
         if ($type == 'detail') {
             $buffer = str_replace('header(', 'if(false) header(', $buffer);
         }
     }
     $buffer = str_replace($originalFile, $cache_file, $buffer);
     $buffer = "<?php\n\$sugar_config['list_max_entries_per_page'] = 1;\n ?>" . $buffer;
     $buffer = str_replace($form_string, '', $buffer);
     $buffer = $this->disableInputs($buffer);
     $xtpl_fp_cache = sugar_fopen($xtpl_cache, 'w');
     fwrite($xtpl_fp_cache, $buffer);
     fclose($xtpl_fp_cache);
     return $xtpl_cache;
 }
Example #16
0
 /**
  * Constructor
  *
  * Sets the theme properties from the defaults passed to it, and loads the file path cache from an external cache
  *
  * @param  $defaults string defaults for the current theme
  */
 public function __construct($defaults)
 {
     // apply parent theme's properties first
     if (isset($defaults['parentTheme'])) {
         $themedef = array();
         include "themes/{$defaults['parentTheme']}/themedef.php";
         foreach ($themedef as $key => $value) {
             if (property_exists(__CLASS__, $key)) {
                 // For all arrays ( except colors and fonts ) you can just specify the items
                 // to change instead of all of the values
                 if (is_array($this->{$key}) && !in_array($key, array('colors', 'fonts'))) {
                     $this->{$key} = array_merge($this->{$key}, $value);
                 } else {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     foreach ($defaults as $key => $value) {
         if (property_exists(__CLASS__, $key)) {
             // For all arrays ( except colors and fonts ) you can just specify the items
             // to change instead of all of the values
             if (is_array($this->{$key}) && !in_array($key, array('colors', 'fonts'))) {
                 $this->{$key} = array_merge($this->{$key}, $value);
             } else {
                 $this->{$key} = $value;
             }
         }
     }
     if (!inDeveloperMode()) {
         if (sugar_is_file($cachedfile = sugar_cached($this->getFilePath() . '/pathCache.php'))) {
             $caches = unserialize(file_get_contents($cachedfile));
             if (isset($caches['jsCache'])) {
                 $this->_jsCache = $caches['jsCache'];
             }
             if (isset($caches['cssCache'])) {
                 $this->_cssCache = $caches['cssCache'];
             }
             if (isset($caches['imageCache'])) {
                 $this->_imageCache = $caches['imageCache'];
             }
             if (isset($caches['templateCache'])) {
                 $this->_templateCache = $caches['templateCache'];
             }
         }
         $cachedfile = sugar_cached($this->getFilePath() . '/spriteCache.php');
         if (!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) {
             $this->_spriteCache = unserialize(sugar_file_get_contents($cachedfile));
         }
     }
     $this->_initialCacheSize = array('jsCache' => count($this->_jsCache), 'cssCache' => count($this->_cssCache), 'imageCache' => count($this->_imageCache), 'templateCache' => count($this->_templateCache), 'spriteCache' => count($this->_spriteCache));
 }
Example #17
0
function preflightCheckJsonFillSchema()
{
    global $mod_strings;
    global $persistence;
    global $sugar_db_version;
    global $manifest;
    global $db;
    if (empty($sugar_db_version)) {
        include 'sugar_version';
    }
    if (empty($manifest)) {
        include $persistence['unzip_dir'] . '/manifest.php';
    }
    ///////////////////////////////////////////////////////////////////////////////
    ////	SCHEMA SCRIPT HANDLING
    $schema = '';
    $alterTableSchemaOut = '';
    $current_version = substr(preg_replace("#[^0-9]#", "", $sugar_db_version), 0, 3);
    $targetVersion = substr(preg_replace("#[^0-9]#", "", $manifest['version']), 0, 3);
    $sqlScript = $persistence['unzip_dir'] . '/scripts/' . $current_version . '_to_' . $targetVersion . '_' . $db->dbType . '.sql';
    $newTables = array();
    logThis('looking for SQL script for DISPLAY at ' . $sqlScript);
    if (file_exists($sqlScript)) {
        $contents = sugar_file_get_contents($sqlScript);
        $schema = "<p><a href='javascript:void(0); toggleNwFiles(\"schemashow\");'>{$mod_strings['LBL_UW_SHOW_SCHEMA']}</a>";
        $schema .= "<div id='schemashow' style='display:none;'>";
        $schema .= "<textarea readonly cols='80' rows='10'>{$contents}</textarea>";
        $schema .= "</div></p>";
    }
    ////	END SCHEMA SCRIPT HANDLING
    ///////////////////////////////////////////////////////////////////////////////
    ob_start();
    echo $schema;
    ob_flush();
}
 /**
  * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
  * properly authenticated user to download a document that they have proper rights to download.
  *
  * @param String $session -- Session ID returned by a previous call to login.
  * @param String $id      -- ID of the document revision to obtain
  * @return new_return_document_revision - Array String 'id' -- The ID of the document revision containing the attachment
  * 												String document_name - The name of the document
  * 												String revision - The revision value for this revision
  *                                         		String 'filename' -- The file name of the attachment
  *                                          	Binary 'file' -- The binary contents of the file.
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 function get_document_revision($session, $id)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_document_revision');
     global $sugar_config;
     $error = new SoapError();
     if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
         return;
     }
     // if
     require_once 'modules/DocumentRevisions/DocumentRevision.php';
     $dr = new DocumentRevision();
     $dr->retrieve($id);
     if (!empty($dr->filename)) {
         $filename = $sugar_config['upload_dir'] . "/" . $dr->id;
         if (filesize($filename) > 0) {
             $contents = sugar_file_get_contents($filename);
         } else {
             $contents = '';
         }
         $contents = base64_encode($contents);
         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
         return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents));
     } else {
         $error->set_error('no_records');
         self::$helperObject->setFaultObject($error);
         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
     }
 }
Example #19
0
 /**
  * Returns the URL for the css file in the current theme. If not found in the current theme, will revert
  * to looking in the base theme.
  *
  * @param  string $cssFileName css file name
  * @param  bool   $returnURL if true, returns URL with unique image mark, otherwise returns path to the file
  * @return string path of css file to include
  */
 public function getCSSURL($cssFileName, $returnURL = true)
 {
     if (isset($this->_cssCache[$cssFileName]) && sugar_is_file(sugar_cached($this->_cssCache[$cssFileName]))) {
         if ($returnURL) {
             return getJSPath("cache/" . $this->_cssCache[$cssFileName]);
         } else {
             return sugar_cached($this->_cssCache[$cssFileName]);
         }
     }
     $cssFileContents = '';
     $defaultFileName = $this->getDefaultCSSPath() . '/' . $cssFileName;
     $fullFileName = $this->getCSSPath() . '/' . $cssFileName;
     if (isset($this->parentTheme) && SugarThemeRegistry::get($this->parentTheme) instanceof SugarTheme && ($filename = SugarThemeRegistry::get($this->parentTheme)->getCSSURL($cssFileName, false)) != '') {
         $cssFileContents .= file_get_contents($filename);
     } else {
         foreach (SugarAutoLoader::existingCustom($defaultFileName) as $cssFile) {
             $cssFileContents .= file_get_contents($cssFile);
         }
     }
     foreach (SugarAutoLoader::existingCustom($fullFileName) as $cssFile) {
         $cssFileContents .= file_get_contents($cssFile);
     }
     if (empty($cssFileContents)) {
         $GLOBALS['log']->warn("CSS File {$cssFileName} not found");
         return false;
     }
     // fix any image references that may be defined in css files
     $cssFileContents = str_ireplace("entryPoint=getImage&", "entryPoint=getImage&themeName={$this->dirName}&", $cssFileContents);
     // create the cached file location
     $cssFilePath = create_cache_directory($fullFileName);
     // if this is the style.css file, prepend the base.css and calendar-win2k-cold-1.css
     // files before the theme styles
     if ($cssFileName == 'style.css' && !isset($this->parentTheme)) {
         if (inDeveloperMode()) {
             $cssFileContents = file_get_contents('include/javascript/yui/build/base/base.css') . $cssFileContents;
         } else {
             $cssFileContents = file_get_contents('include/javascript/yui/build/base/base-min.css') . $cssFileContents;
         }
     }
     // minify the css
     if (!inDeveloperMode() && !sugar_is_file($cssFilePath)) {
         $cssFileContents = cssmin::minify($cssFileContents);
     }
     // now write the css to cache
     sugar_file_put_contents($cssFilePath, $cssFileContents);
     // make sure that there is the font folder in the cache for the given theme
     $path = sugar_cached($this->getFilePath() . '/font');
     if (!sugar_is_dir($path)) {
         sugar_mkdir($path, null, true);
         $defaultPath = $this->getDefaultFontPath();
         foreach (glob($defaultPath . "/*") as $filename) {
             $name = substr($filename, strrpos($filename, '/'));
             sugar_file_put_contents($path . $name, sugar_file_get_contents($filename));
         }
     }
     $this->_cssCache[$cssFileName] = $fullFileName;
     if ($returnURL) {
         return getJSPath("cache/" . $fullFileName);
     }
     return sugar_cached($fullFileName);
 }
Example #20
0
function preflightCheckJsonFillSchema()
{
    global $mod_strings;
    global $persistence;
    global $sugar_db_version;
    global $manifest;
    global $db;
    if (empty($sugar_db_version)) {
        include 'sugar_version.php';
    }
    if (empty($manifest)) {
        include $persistence['unzip_dir'] . '/manifest.php';
    }
    ///////////////////////////////////////////////////////////////////////////////
    ////	SCHEMA SCRIPT HANDLING
    $schema = '';
    $alterTableSchemaOut = '';
    $origVersion = implodeVersion($sugar_db_version);
    $destVersion = implodeVersion($manifest['version']);
    $script_name = $db->getScriptType();
    $sqlScript = $persistence['unzip_dir'] . "/scripts/{$origVersion}_to_{$destVersion}_{$script_name}.sql";
    $newTables = array();
    logThis('looking for SQL script for DISPLAY at ' . $sqlScript);
    if (file_exists($sqlScript)) {
        $contents = sugar_file_get_contents($sqlScript);
        $schema = "<p><a href='javascript:void(0); toggleNwFiles(\"schemashow\");'>{$mod_strings['LBL_UW_SHOW_SCHEMA']}</a>";
        $schema .= "<div id='schemashow' style='display:none;'>";
        $schema .= "<textarea readonly cols='80' rows='10'>{$contents}</textarea>";
        $schema .= "</div></p>";
    }
    ////	END SCHEMA SCRIPT HANDLING
    ///////////////////////////////////////////////////////////////////////////////
    ob_start();
    echo $schema;
    ob_flush();
}
Example #21
0
function doSearch($index, $queryString, $start = 0, $amount = 20)
{
    $cachePath = 'cache/modules/AOD_Index/QueryCache/' . md5($queryString);
    if (is_file($cachePath)) {
        $mTime = getCorrectMTime($cachePath);
        if ($mTime > time() - 5 * 60) {
            $hits = unserialize(sugar_file_get_contents($cachePath));
        }
    }
    if (!isset($hits)) {
        $tmphits = $index->find($queryString);
        $hits = array();
        foreach ($tmphits as $hit) {
            $newHit = new stdClass();
            $newHit->record_module = $hit->record_module;
            $newHit->record_id = $hit->record_id;
            $newHit->score = $hit->score;
            $hits[] = $newHit;
        }
        //Cache results so pagination is nice and snappy.
        cacheQuery($queryString, $hits);
    }
    $total = count($hits);
    $hits = array_slice($hits, $start, $amount);
    $res = array('total' => $total, 'hits' => $hits);
    return $res;
}