public function loadModel($id)
 {
     $model = Docs::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#2
0
 public function action_sidebar()
 {
     $sidebar = Docs::content('contents');
     // For some reason the list is getting br tags.
     $sidebar = str_replace('<br />', '', $sidebar);
     // Make it work locally
     if ($_SERVER['LARAVEL_ENV'] == 'local') {
         $sidebar = str_replace('/docs', URL::to() . 'docs', $sidebar);
     }
     return $sidebar;
 }
示例#3
0
 private function ini()
 {
     if (!$this->ini) {
         $this->_precision = Yii::app()->user->getSetting('company.precision');
         $this->iVatRate = Item::model()->findByPK($this->item_id)->vat;
         $this->rate = Currates::model()->GetRate($this->currency_id);
         if ($this->doc_rate == 0) {
             $doc = Docs::model()->findByPk($this->doc_id);
             $this->doc_rate = Currates::model()->GetRate($doc->currency_id);
         }
         $this->ini != $this->ini;
     }
 }
示例#4
0
 public function __construct($method, $param)
 {
     $this->param = new ReflectionParameter($method, $param);
     $this->name = $this->param->name;
     if ($this->param->isDefaultValueAvailable()) {
         $this->default = Docs::dump($this->param->getDefaultValue());
     }
     if ($this->param->isPassedByReference()) {
         $this->reference = TRUE;
     }
     if ($this->param->isOptional()) {
         $this->optional = TRUE;
     }
 }
示例#5
0
 public function __construct($class, $method)
 {
     $this->method = new ReflectionMethod($class, $method);
     $this->class = $parent = $this->method->getDeclaringClass();
     if ($modifiers = $this->method->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     do {
         if ($parent->hasMethod($method) and $comment = $parent->getMethod($method)->getDocComment()) {
             // Found a description for this method
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $tags) = Docs::parse($comment);
     if ($file = $this->class->getFileName()) {
         $this->source = Docs::source($file, $this->method->getStartLine(), $this->method->getEndLine());
     }
     if (isset($tags['param'])) {
         $params = array();
         foreach ($this->method->getParameters() as $i => $param) {
             $param = new Docs_Method_Param(array($this->method->class, $this->method->name), $i);
             if (isset($tags['param'][$i])) {
                 preg_match('/^(\\S+)(?:\\s*(?:\\$' . $param->name . '\\s*)?(.+))?$/', $tags['param'][$i], $matches);
                 $param->type = $matches[1];
                 if (isset($matches[2])) {
                     $param->description = $matches[2];
                 }
             }
             $params[] = $param;
         }
         $this->params = $params;
         unset($tags['param']);
     }
     if (isset($tags['return'])) {
         foreach ($tags['return'] as $return) {
             if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $return, $matches)) {
                 $this->return[] = array($matches[1], isset($matches[2]) ? $matches[2] : '');
             }
         }
         unset($tags['return']);
     }
     $this->tags = $tags;
 }
示例#6
0
 public function docsTest()
 {
     $types = Doctype::find()->All();
     foreach ($types as $type) {
         $docs = Docs::find()->where(["doctype" => $type->id])->orderBy('docnum')->All();
         $num = 0;
         foreach ($docs as $doc) {
             if ($num != 0) {
                 if ($num == $doc->docnum) {
                     $this->errors[] = 'Duplicate documenet number:' . $doc->docnum . ' id: ' . $doc->id . " type: " . $type->name;
                 }
                 if ($num + 1 != $doc->docnum) {
                     $this->errors[] = 'Invalid documenet number:' . $doc->docnum . ' id: ' . $doc->id . " type: " . $type->name;
                 }
             }
             $num = $doc->docnum;
         }
     }
 }
示例#7
0
 /**
  * Loads a class and uses [reflection](http://php.net/reflection) to parse
  * the class. Reads the class modifiers, constants and comment. Parses the
  * comment to find the description and tags.
  *
  * @param   string   class name
  * @return  void
  */
 public function __construct($class)
 {
     $this->class = new ReflectionClass($class);
     if ($modifiers = $this->class->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if ($constants = $this->class->getConstants()) {
         foreach ($constants as $name => $value) {
             $this->constants[$name] = Docs::debug($value);
         }
     }
     $parent = $this->class;
     do {
         if ($comment = $parent->getDocComment()) {
             // Found a description for this class
             break;
         }
     } while ($parent = $parent->getParentClass());
     list($this->description, $this->tags) = Docs::parse($comment);
 }
示例#8
0
 public function __construct($class, $property)
 {
     $property = new ReflectionProperty($class, $property);
     list($description, $tags) = Docs::parse($property->getDocComment());
     $this->description = $description;
     if ($modifiers = $property->getModifiers()) {
         $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
     }
     if (isset($tags['var'])) {
         if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) {
             $this->type = $matches[1];
             if (isset($matches[2])) {
                 $this->description = $matches[2];
             }
         }
     }
     $this->property = $property;
     if ($property->isStatic()) {
         $this->value = Docs::debug($property->getValue($class));
     }
 }
示例#9
0
 public function testReplaceVariables()
 {
     $quote = $this->quotes('docsTest');
     $contact = $this->contacts('testAnyone');
     $account = $this->accounts('testQuote');
     $attrs = $quote->getAttributes();
     $contactAttrs = $contact->getAttributes();
     $accountAttrs = $account->getAttributes();
     // ensure that tokens with references to customized class names get properly replaced
     $quoteTemplate = array();
     foreach ($attrs as $name => $val) {
         $quoteTemplate[$name] = "{" . $name . "}";
     }
     foreach ($contactAttrs as $name => $val) {
         $quoteTemplate[$name] = "{" . self::$contactsField . ".{$name}}";
     }
     foreach ($accountAttrs as $name => $val) {
         $quoteTemplate[$name] = "{" . self::$accountsField . ".{$name}}";
     }
     foreach (array_intersect(array_keys($contactAttrs), array_keys($attrs), array_keys($accountAttrs)) as $name) {
         unset($quoteTemplate[$name]);
         unset($attrs[$name]);
         unset($contactAttrs[$name]);
         unset($accountAttrs[$name]);
     }
     // add quotes template-specific token
     $quoteTemplate['dateNow'] = '{dateNow}';
     $quoteTemplate['lineItems'] = '{lineItems}';
     $quoteTemplate['quoteOrInvoice'] = '{quoteOrInvoice}';
     $quoteTemplate = CJSON::encode($quoteTemplate);
     $str = Docs::replaceVariables($quoteTemplate, $quote, array(), false, false);
     $this->assertEquals(array_merge(array_map(function ($elem) {
         return (string) $elem;
     }, $attrs), array_map(function ($elem) {
         return (string) $elem;
     }, $contactAttrs), array_map(function ($elem) {
         return (string) $elem;
     }, $accountAttrs), array('lineItems' => preg_replace("/\r|\n/", "", $quote->productTable(true)), 'dateNow' => date("F d, Y", time()), 'quoteOrInvoice' => Yii::t('quotes', $quote->type == 'invoice' ? 'Invoice' : Modules::displayName(false, "Quotes")))), CJSON::decode($str));
 }
示例#10
0
 public static function url($class, $havedir = false, $haveext = false)
 {
     $url = 'api/' . DOCS_PROJECT . '/';
     // . ($havedir ? '' : '/' . Docs::_class2url( $class )) . '/' ;
     if ($havedir) {
         list($dir) = explode('/', $class);
     } else {
         $dir = Docs::_class2url($class);
         $url .= $dir . '/';
     }
     if ($dir == 'classes') {
         $ext = '.class' . EXT;
         $class = str_replace('_', '/', $class);
     } elseif ($dir == 'models') {
         $ext = '.model' . EXT;
         $class = str_replace('_', '/', $class);
     } elseif ($dir == 'shell') {
         $ext = '.shell' . EXT;
         $class = strtolower($class);
     } elseif ($dir == 'admin') {
         $ext = '.admin' . EXT;
         $class = strtolower($class);
     } elseif ($dir == 'controllers') {
         $ext = '.controller' . EXT;
         $class = strtolower($class);
     } elseif ($dir == 'config') {
         $ext = '.config' . EXT;
     } elseif ($dir == 'i18n') {
         $ext = '.lang';
     }
     if ($haveext) {
         $url .= $class;
     } else {
         $url .= $class . $ext;
     }
     return Core::url($url);
 }
 public static function recordEmailSent(Campaign $campaign, Contacts $contact)
 {
     $action = new Actions();
     // Disable the unsightly notifications for loads of emails:
     $action->scenario = 'noNotif';
     $now = time();
     $action->associationType = 'contacts';
     $action->associationId = $contact->id;
     $action->associationName = $contact->firstName . ' ' . $contact->lastName;
     $action->visibility = $contact->visibility;
     $action->type = 'email';
     $action->assignedTo = $contact->assignedTo;
     $action->createDate = $now;
     $action->completeDate = $now;
     $action->complete = 'Yes';
     $action->actionDescription = '<b>' . Yii::t('marketing', 'Campaign') . ': ' . $campaign->name . "</b>\n\n" . Yii::t('marketing', 'Subject') . ": " . Docs::replaceVariables($campaign->subject, $contact) . "\n\n" . Docs::replaceVariables($campaign->content, $contact);
     if (!$action->save()) {
         throw new CException('Campaing email action history record failed to save with validation errors: ' . CJSON::encode($action->errors));
     }
 }
示例#12
0
echo $form->textField($this->model, 'bcc', array('id' => 'email-bcc', 'tabindex' => '3'));
?>
        </div>
    </div>
        <div class="row email-input-row">
            <?php 
//echo $form->label($this->model, 'subject', array('class' => 'x2-email-label'));
echo $form->textField($this->model, 'subject', array('tabindex' => '4', 'class' => 'x2-default-field', 'data-default-text' => CHtml::encode(Yii::t('app', 'Subject'))));
?>
        </div>
        <?php 
if (!$this->disableTemplates) {
    ?>
        <div class="row email-input-row">
            <?php 
    $templateList = Docs::getEmailTemplates($type, $associationType);
    $target = $this->model->targetModel;
    echo $form->label($this->model, 'template', array('class' => 'x2-email-label'));
    if (!isset($this->template) && $target instanceof Quote && isset($target->template) && !isset($this->model->template)) {
        // When sending an InlineEmail targeting a Quote
        list($templateName, $selectedTemplate) = Fields::nameAndId($target->template);
        $this->model->template = $selectedTemplate;
    }
    echo $form->dropDownList($this->model, 'template', array('0' => Yii::t('docs', 'Custom Message')) + $templateList, array('id' => 'email-template'));
    ?>
        </div>
        <?php 
}
?>
        <div class="row" id="email-message-box">
        <?php 
示例#13
0
文件: track.php 项目: Kapodastr/grow
			</ul>
				
		</div>


	</div>   <!-- /.col-md-8 -->



</div> <!-- /.row -->
 
	<br>Презентации <br>

	<?php 
echo $form->dropDownList($track, 'Docs', CHtml::listData(Docs::model()->findAll(), 'id', 'title'), array("multiple" => true));
?>
	
	<br>Алгоритмы<br>

	<?php 
echo $form->dropDownList($track, 'Algorithms', CHtml::listData(Algorithms::model()->findAll(), 'id', 'title'), array("multiple" => true));
?>
	

	<br><br>
	<button type="submit" class="btn btn-success btn-lg">Сохранить</button>

<?php 
$this->endWidget();
?>
示例#14
0
        $quoteAttributes[$Quote . Yii::t('quotes', "Date printed/emailed")] = '{dateNow}';
        $quoteAttributes[$Quote . Yii::t('quotes', '{quote} or Invoice', array('{quote}' => $modTitles['quote']))] = '{quoteOrInvoice}';
        foreach (Quote::model()->getAttributeLabels() as $fieldName => $label) {
            $index = $Quote . "{$label}";
            $quoteAttributes[$index] = "{" . $fieldName . "}";
        }
    }
    if ($model->type === 'email') {
        $js = 'x2.insertableAttributes = ' . CJSON::encode(array(Yii::t('contacts', '{contact} Attributes', array('{contact}' => $modTitles['contact'])) => $attributes)) . ';';
    } else {
        $js = 'x2.insertableAttributes = ' . CJSON::encode(array(Yii::t('docs', '{contact} Attributes', array('{contact}' => $modTitles['contact'])) => $contactAttributes, Yii::t('docs', '{account} Attributes', array('{account}' => $modTitles['account'])) => $accountAttributes, Yii::t('docs', '{quote} Attributes', array('{quote}' => $modTitles['quote'])) => $quoteAttributes)) . ';';
    }
}
if ($model->type === 'email') {
    // allowable association types
    $associationTypeOptions = Docs::modelsWhichSupportEmailTemplates();
    // insertable attributes by model type
    $insertableAttributes = array();
    foreach ($associationTypeOptions as $modelName => $label) {
        $insertableAttributes[$modelName] = array();
        foreach (X2Model::model($modelName)->getAttributeLabels() as $fieldName => $label) {
            $insertableAttributes[$modelName][$label] = '{' . $fieldName . '}';
        }
    }
    Yii::app()->clientScript->registerScript('createEmailTemplateJS', "\n\n;(function () {\n\nvar insertableAttributes = " . CJSON::encode($insertableAttributes) . ";\n\n// reinitialize ckeditor instance with new set of insertable attributes whenever the record type\n// selector is changed\n\$('#email-association-type').change (function () {\n    \n    var data = window.docEditor.getData ();\n    window.docEditor.destroy (true);\n    \$('#input').val (data);\n    var recordInsertableAttributes = {};\n    recordInsertableAttributes[\$(this).val () + ' Attributes'] = \n        insertableAttributes[\$(this).val ()];\n    instantiateDocEditor (recordInsertableAttributes);\n});\n\n}) ();\n\n");
}
$js .= '
var typingTimer;

function autosave() {
	window.docEditor.updateElement();
示例#15
0
 public function run()
 {
     if (Yii::app()->user->isGuest) {
         Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/site/login'));
     }
     $this->attachBehaviors($this->behaviors);
     // Safety net of handlers - they ensure that errors can be caught and seen easily:
     $scenario = 'custom';
     if (empty($this->model)) {
         $model = new InlineEmail();
     } else {
         $model = $this->model;
     }
     if (isset($_POST['contactFlag'])) {
         $model->contactFlag = $_POST['contactFlag'];
     }
     $makeEvent = isset($_GET['skipEvent']) ? !(bool) $_GET['skipEvent'] : 1;
     // Check to see if the user is requesting a new template
     if (isset($_GET['template'])) {
         $scenario = 'template';
     }
     $model->setScenario($scenario);
     $attachments = array();
     if (isset($_POST['InlineEmail'])) {
         // This could indicate either a template change or a form submission.
         $model->attributes = $_POST['InlineEmail'];
         // Prepare attachments that may have been uploaded on-the-fly (?)
         $mediaLibraryUsed = false;
         // is there an attachment from the media library?
         if (isset($_POST['AttachmentFiles'], $_POST['AttachmentFiles']['id'], $_POST['AttachmentFiles']['types'])) {
             $ids = $_POST['AttachmentFiles']['id'];
             $types = $_POST['AttachmentFiles']['types'];
             $attachments = array();
             for ($i = 0; $i < count($ids); $i++) {
                 $type = $types[$i];
                 switch ($type) {
                     case 'temp':
                         // attachment is a temp file
                         $tempFile = TempFile::model()->findByPk($ids[$i]);
                         $attachments[] = array('filename' => $tempFile->name, 'folder' => $tempFile->folder, 'type' => $type, 'id' => $tempFile->id);
                         break;
                     case 'media':
                         // attachment is from media library
                         $mediaLibraryUsed = true;
                         $media = Media::model()->findByPk($ids[$i]);
                         $attachments[] = array('filename' => $media->fileName, 'folder' => $media->uploadedBy, 'type' => $type, 'id' => $media->id);
                         break;
                     default:
                         throw new CException('Invalid attachment type: ' . $type);
                 }
             }
         }
         $model->attachments = $attachments;
         // Validate/prepare the body, and send if no problems occur:
         $sendStatus = array_fill_keys(array('code', 'message'), '');
         $failed = false;
         $message = '';
         $postReplace = isset($_GET['postReplace']) ? $_GET['postReplace'] : 0;
         if (isset($_GET['loadTemplate'])) {
             // A special override for when it's not possible to include the template in $_POST
             $model->template = $_GET['loadTemplate'];
         }
         if ($model->prepareBody($postReplace)) {
             if ($scenario != 'template') {
                 // Sending the email, not merely requesting a template change
                 //
                 // First check that the user has permission to use the
                 // specified credentials:
                 if ($model->credId != Credentials::LEGACY_ID) {
                     if (!Yii::app()->user->checkAccess('CredentialsSelect', array('model' => $model->credentials))) {
                         $this->respond(Yii::t('app', 'Did not send email because you do not have ' . 'permission to use the specified credentials.'), 1);
                     }
                 }
                 $sendStatus = $model->send($makeEvent);
                 // $sendStatus = array('code'=>'200','message'=>'sent (testing)');
                 $failed = $sendStatus['code'] != '200';
                 $message = $sendStatus['message'];
             } else {
                 if ($model->modelName == 'Quote' && empty($model->template)) {
                     // Fill in the gap with the default / "semi-legacy" quotes view
                     $model->message = $this->controller->renderPartial('application.modules.quotes.views.quotes.print', array('model' => $model->targetModel, 'email' => true), true);
                     // Add a linebreak at the beginning for user-entered notes in the email:
                     $model->insertInBody('<br />', 1);
                 }
             }
         }
         // Populate response data:
         $modelHasErrors = $model->hasErrors();
         $failed = $failed || $modelHasErrors;
         $response = array('scenario' => $scenario, 'sendStatus' => $sendStatus, 'attributes' => $model->attributes, 'modelErrors' => $model->errors, 'modelHasErrors' => $modelHasErrors, 'modelErrorHtml' => CHtml::errorSummary($model, Yii::t('app', "Please fix the following errors:"), null, array('style' => 'margin-bottom: 5px;')));
         if ($scenario == 'template') {
             // There's a chance the inline email form is switching gears into
             // quote mode, in which case we need to include templates and
             // insertable attributes for setting it all up properly:
             $response['insertableAttributes'] = $model->insertableAttributes;
             $templates = array(0 => Yii::t('docs', 'Custom Message')) + Docs::getEmailTemplates($model->modelName == 'Quote' ? 'quote' : 'email', $_POST['associationType']);
             $response['templateList'] = array();
             foreach ($templates as $id => $templateName) {
                 $response['templateList'][] = array('id' => $id, 'name' => $templateName);
             }
         }
         $this->mergeResponse($response);
         $this->respond($message, $failed);
     } else {
         $this->respond(Yii::t('app', 'Inline email model missing from the request to the server.'), true);
     }
 }
示例#16
0
 public function actionDeleteFileFolder()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_POST['type'], $_POST['id'])) {
         if ($_POST['type'] === 'folder') {
             $model = DocFolders::model()->findByPk($_POST['id']);
             if (is_null($model)) {
                 throw new CHttpException(404, 'Folder not found.');
             }
             if (!$model->checkRecursiveDeletePermissions()) {
                 $this->denied();
             }
         } elseif ($_POST['type'] === 'doc') {
             $model = Docs::model()->findByPk($_POST['id']);
             if (is_null($model)) {
                 throw new CHttpException(404, 'File not found.');
             }
             if (!$this->checkPermissions($model, 'delete')) {
                 $this->denied();
             }
         } else {
             throw new CHttpException(400, 'Bad request.');
         }
         $model->delete();
     } else {
         throw new CHttpException(400, 'Bad request.');
     }
 }
示例#17
0
 public function testReplaceVariables()
 {
     $quote = $this->quotes('docsTest');
     $contact = $this->contacts('testAnyone');
     $attrs = $quote->getAttributes();
     $contactAttrs = $contact->getAttributes();
     //        $quoteTemplate = array ();
     //        foreach ($attrs as $name => &$val) {
     //            $quoteTemplate[$name] = "{Quote.$name}";
     //        }
     //        foreach ($contactAttrs as $name => &$val) {
     //            $quoteTemplate[$name] = "{Contact.$name}";
     //        }
     //        foreach (array_intersect (array_keys ($contactAttrs), array_keys ($attrs)) as $name) {
     //            unset ($quoteTemplate[$name]);
     //            unset ($attrs[$name]);
     //            unset ($contactAttrs[$name]);
     //        }
     //        $quoteTemplate = CJSON::encode ($quoteTemplate);
     //        $str = Docs::replaceVariables ($quoteTemplate, $quote, array (), false , false);
     //        $this->assertEquals (
     //            array_merge (
     //                array_map (function ($elem) { return (string) $elem; }, $attrs),
     //                array_map (function ($elem) { return (string) $elem; }, $contactAttrs)
     //            ),
     //            CJSON::decode ($str)
     //        );
     // ensure that tokens with references to customized class names get properly replaced
     $quoteTemplate = array();
     foreach ($attrs as $name => $val) {
         $quoteTemplate[$name] = "{" . self::$customQuotesTitle . ".{$name}}";
     }
     foreach ($contactAttrs as $name => $val) {
         $quoteTemplate[$name] = "{" . self::$customContactsTitle . ".{$name}}";
     }
     foreach (array_intersect(array_keys($contactAttrs), array_keys($attrs)) as $name) {
         unset($quoteTemplate[$name]);
         unset($attrs[$name]);
         unset($contactAttrs[$name]);
     }
     // add quotes template-specific token
     $quoteTemplate['dateNow'] = '{' . self::$customQuotesTitle . '.quoteOrInvoice}';
     $quoteTemplate = CJSON::encode($quoteTemplate);
     $str = Docs::replaceVariables($quoteTemplate, $quote, array(), false, false);
     $this->assertEquals(array_merge(array_map(function ($elem) {
         return (string) $elem;
     }, $attrs), array_map(function ($elem) {
         return (string) $elem;
     }, $contactAttrs), array('dateNow' => Yii::t('quotes', $quote->type == 'invoice' ? 'Invoice' : self::$customQuotesTitle))), CJSON::decode($str));
     // old test
     //        $this->markTestSkipped('This test has been very badly broken by '
     //                . 'changes made to X2Model.getAttribute and '
     //                . 'Formatter.replaceVariables which apparently make it so that '
     //                . 'no combination of arguments sent to Docs.replaceVariables '
     //                . 'versus to X2Model.getAttribute produce an equivalent list '
     //                . 'of values. Thus, for now, abandon hope of fixing it.');
     //
     //		// Test replacement in emails:
     //		$contact = $this->contacts('testAnyone');
     //		$textIn = array();
     //		$textOutExpected = array();
     //		$delimiter = "\n@@|@@\n";
     //		foreach($contact->attributes as $name=>$value) {
     //			$textIn[] = '{'.$name.'}';
     //			$textOutExpected[] = $contact->renderAttribute($name, false);
     //		}
     //		$textIn = implode($delimiter,$textIn);
     //		$textOutExpected = implode($delimiter,$textOutExpected);
     //		$textOut = Docs::replaceVariables($textIn,$contact);
     //		$this->assertEquals($textOutExpected,$textOut,'Failed asserting that email template replacement succeeded.');
     //
     //		// Test replacement in Quote bodies:
     //		$quote = $this->quotes('docsTest');
     //		$classes = array(
     //			'Accounts',
     //			'Contacts',
     //			'Quote'
     //			); // In that order
     //		$models = array(
     //			'Accounts' => $this->accounts('testQuote'),
     //			'Contacts' => $this->contacts('testAnyone'),
     //			'Quote' => $this->quotes('docsTest'),
     //		);
     //		$textIn = array();
     //		$textOutExpected = array();
     //		$delimiter = "\n*|*\n";
     //
     //		foreach($classes as $class) {
     //			$classNick = rtrim($class,'s');
     //			$attrs = array_keys($class::model()->attributeLabels());
     //			foreach($attrs as $attribute) {
     //				$textIn[] = '{'.$classNick.'.'.$attribute.'}';
     //				$textOutExpected[] =  empty($models[$class])?'':$models[$class]->renderAttribute($attribute, false);
     //			}
     //		}
     //		$textIn = implode($delimiter,$textIn);
     //		$textOutExpected = implode($delimiter,$textOutExpected);
     //		$textOut = Docs::replaceVariables($textIn,$quote);
     //		$this->assertEquals($textOutExpected,$textOut, 'Failed asserting that Quote template replacement succeeded.');
     //
     //
 }
示例#18
0
 public function paramRules()
 {
     $parentRules = parent::paramRules();
     $parentRules['options'] = array_merge($parentRules['options'], array(array('name' => 'to', 'label' => Yii::t('studio', 'To:'), 'type' => 'email'), array('name' => 'template', 'label' => Yii::t('studio', 'Template'), 'type' => 'dropdown', 'defaultVal' => '', 'options' => array('' => Yii::t('studio', 'Custom')) + Docs::getEmailTemplates('email', 'Contacts')), array('name' => 'subject', 'label' => Yii::t('studio', 'Subject'), 'optional' => 1), array('name' => 'cc', 'label' => Yii::t('studio', 'CC:'), 'optional' => 1, 'type' => 'email'), array('name' => 'bcc', 'label' => Yii::t('studio', 'BCC:'), 'optional' => 1, 'type' => 'email'), array('name' => 'body', 'label' => Yii::t('studio', 'Message'), 'optional' => 1, 'type' => 'richtext')));
     return $parentRules;
 }
示例#19
0
文件: Modules.php 项目: xl602/X2CRM
 /**
  * Renames module
  * @param string $newTitle 
  * @return bool true for success, false for failure
  */
 public function retitle($newTitle)
 {
     $oldTitle = $this->title;
     $this->title = $newTitle;
     if ($this->save()) {
         // if it's a static page, rename the doc too
         if ($this->name === 'document') {
             $doc = Docs::model()->findByAttributes(array('name' => $oldTitle));
             $doc->name = $this->title;
             $doc->save();
         }
         // Clear cached display names
         self::$_displayNames = array();
         return true;
     } else {
         return false;
     }
 }
示例#20
0
 public function import()
 {
     //add warehouse
     $array = $this->read();
     //companies
     $company = $this->parseLine($array['companies'][0]);
     $prefix = $company[1];
     //echo $prefix;
     $this->saveSetting('company.name', $company[0]);
     $this->saveSetting('company.vat.id', $company[3]);
     $this->saveSetting('company.address', $company[4]);
     $this->saveSetting('company.city', $company[5]);
     $this->saveSetting('company.zip', $company[6]);
     $this->saveSetting('company.phone', $company[7]);
     $this->saveSetting('company.fax', $company[8]);
     $this->saveSetting('company.website', $company[9]);
     $this->saveSetting('company.tax.rate', $company[10]);
     $this->saveSetting('company.tax.irs', $company[11]);
     //$this->saveSetting('account.100.srctax', $company[12]);
     $this->saveSetting('company.tax.vat', $company[13]);
     //exit;
     ///*
     if (isset($array['accounts'])) {
         $this->imprtAccounts($array['accounts'], $prefix);
     }
     if (isset($array['items'])) {
         $this->imprtItems($array['items'], $prefix);
     }
     if (isset($array['docs'])) {
         $this->imprtDocs($array['docs'], $prefix);
     }
     if (isset($array['cheques'])) {
         $this->imprtCheques($array['cheques'], $prefix);
     }
     if (isset($array['docdetails'])) {
         $this->imprtDocdetails($array['docdetails'], $prefix);
     }
     if (isset($array['transactions'])) {
         $this->imprtTransactions($array['transactions'], $prefix);
     }
     if (isset($array['bankbook'])) {
         $this->imprtBankbooks($array['bankbook'], $prefix);
     }
     if (isset($array['correlation'])) {
         $this->imprtCorrelations($array['correlation'], $prefix);
     }
     //*/
     //vat rate
     $acc = Accounts::model()->findByPk(100);
     $acc->src_tax = $company[12];
     $acc->save();
     $acc = Accounts::model()->findByPk(101);
     $acc->src_tax = $company[12];
     $acc->save();
     //add warehouse
     //add genral item
     //get transaction num
     $this->saveSetting('company.transaction', Transactions::getMax() + 1);
     //get docnums
     $types = Doctype::model()->findAll();
     foreach ($types as $type) {
         $type->last_docnum = Docs::getMax($type->id);
         $type->save();
     }
     //contacthist
     //contacts??
     //tranrep??
 }
示例#21
0
 /**
  * Prepare the email body for sending or customization by the user.
  */
 public function prepareBody($postReplace = 0)
 {
     if (!$this->validate()) {
         return false;
     }
     // Replace the existing body, if any, with a template, i.e. for initial
     // set-up or an automated email.
     if ($this->scenario === 'template') {
         // Get the template and associated model
         if (!empty($this->templateModel)) {
             if ($this->templateModel->emailTo !== null) {
                 $this->to = Docs::replaceVariables($this->templateModel->emailTo, $this->targetModel, array(), false, false);
             }
             // Replace variables in the subject and body of the email
             $this->subject = Docs::replaceVariables($this->templateModel->subject, $this->targetModel);
             // if(!empty($this->targetModel)) {
             $this->message = Docs::replaceVariables($this->templateModel->text, $this->targetModel, array('{signature}' => self::insertedPattern('signature', $this->signature)));
             // } else {
             // $this->insertInBody('<span style="color:red">'.Yii::t('app','Error: attempted using a template, but the referenced model was not found.').'</span>');
             // }
         } else {
             // No template?
             $this->message = self::emptyBody();
             $this->insertSignature();
         }
     } else {
         if ($postReplace) {
             $this->subject = Docs::replaceVariables($this->subject, $this->targetModel);
             $this->message = Docs::replaceVariables($this->message, $this->targetModel);
         }
     }
     return true;
 }
示例#22
0
 /**
  * Echoes 'true' if User has permission, 'false' otherwise
  * @param int id id of doc model  
  */
 public function actionAjaxCheckEditPermission($id)
 {
     if (!isset($id)) {
         echo 'failure';
         return;
     }
     $doc = Docs::model()->findByPk($id);
     if (isset($doc)) {
         $canEdit = $doc->checkEditPermissions() ? 'true' : 'false';
     } else {
         $canEdit = 'false';
     }
     echo $canEdit;
     return;
 }
示例#23
0
 public function make()
 {
     $this->id = rand(0, 999999);
     //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,);
     //$this->docArr=array(0=>0,305=>0,300=>0,);
     $bkmv = '';
     //$this->line=1;
     $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec');
     $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime');
     $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date . ":00", $yiidatetimesec));
     $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date . ":00", $yiidatetimesec));
     //$types=array(3,4,9,11,13,14);
     //accounts
     $criteria = new CDbCriteria();
     $accounts = Accounts::model()->findAll($criteria);
     $record = array('id' => 'B110', 'name' => OpenFormatType::model()->getDesc('B110'), 'count' => 0);
     foreach ($accounts as $account) {
         $this->line++;
         $bkmv .= $account->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //items
     $criteria = new CDbCriteria();
     $items = Item::model()->findAll($criteria);
     $record = array('id' => 'M100', 'name' => OpenFormatType::model()->getDesc('M100'), 'count' => 0);
     foreach ($items as $item) {
         $this->line++;
         $bkmv .= $item->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //
     //transactions
     $criteria = new CDbCriteria();
     $criteria->condition = "valuedate BETWEEN :from_date AND :to_date";
     $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date);
     $transactions = Transactions::model()->findAll($criteria);
     $record = array('id' => 'B100', 'name' => OpenFormatType::model()->getDesc('B100'), 'count' => 0);
     foreach ($transactions as $transaction) {
         $this->line++;
         $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //docs
     $criteria = new CDbCriteria();
     $criteria->condition = "due_date BETWEEN :from_date AND :to_date";
     $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date);
     $docs = Docs::model()->findAll($criteria);
     //OpenFormatType::model()->getDesc('C100')
     $record = array('id' => 'C100', 'name' => OpenFormatType::model()->getDesc('C100'), 'count' => 0);
     $d110 = array('id' => 'D110', 'name' => OpenFormatType::model()->getDesc('D110'), 'count' => 0);
     $d120 = array('id' => 'D120', 'name' => OpenFormatType::model()->getDesc('D120'), 'count' => 0);
     foreach ($docs as $doc) {
         if ($doc->docType->openformat != '0') {
             $this->line++;
             $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date);
             foreach ($doc->docDetailes as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d110['count']++;
             }
             foreach ($doc->docCheques as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d120['count']++;
             }
             $type = $doc->getType();
             $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0;
             $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total;
             $record['count']++;
         }
     }
     $this->iniArr[] = $record;
     $this->iniArr[] = $d110;
     $this->iniArr[] = $d120;
     $company = Settings::model()->findByPk('company.name');
     //A100
     $bkmv = $company->a100(1, $this->id) . $bkmv;
     //Z900
     $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1);
     $bkmvFile = new Files();
     $bkmvFile->name = 'bkmvdata.txt';
     $bkmvFile->path = 'openformat/';
     //
     $bkmvFile->expire = 360;
     $bkmvFile->save();
     $bkmvFile->writeFile($bkmv);
     $this->bkmvId = $bkmvFile->id;
     //A000
     $ini = $company->a000(1, $this->id, $this->line + 1);
     foreach ($this->iniArr as $line) {
         $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n";
     }
     //Z
     $iniFile = new Files();
     $iniFile->name = 'ini.txt';
     $iniFile->path = 'openformat/';
     //
     $iniFile->expire = 360;
     $iniFile->save();
     $iniFile->writeFile($ini);
     $this->iniId = $iniFile->id;
     return $this->id;
 }
示例#24
0
 public function getDocs()
 {
     return $this->hasMany(Docs::className(), array('account_id' => 'id'));
 }
示例#25
0
 private function getChildren($option = null)
 {
     $children = array('folders' => array(), 'docs' => array());
     $folderCriteria = new CDbCriteria();
     if ($option === 'root') {
         $folderCriteria->condition = 'parentFolder IS NULL AND id > 0';
     } else {
         $folderCriteria->compare('parentFolder', $this->id);
     }
     $folderCriteria->mergeWith($this->getAccessCriteria());
     $folderCriteria->order = 'name ASC';
     $children['folders'] = DocFolders::model()->findAll($folderCriteria);
     $docsCriteria = new CDbCriteria();
     $doc = Docs::model();
     if ($option === 'root') {
         $docsCriteria->condition = 'folderId IS NULL AND type NOT IN ("email","quote")';
     } elseif ($option === self::TEMPLATES_FOLDER_ID) {
         $docsCriteria->condition = 'folderId IS NULL AND type IN ("email","quote")';
     } else {
         $docsCriteria->compare('folderId', $this->id);
     }
     $docsCriteria->mergeWith($doc->getAccessCriteria());
     $docsCriteria->order = 'name ASC';
     $children['docs'] = Docs::model()->findAll($docsCriteria);
     return $children;
 }
示例#26
0
 /**
  * @param array $gvSelection array of ids of records to perform mass action on
  */
 public function execute(array $gvSelection)
 {
     if (Yii::app()->controller->modelClass !== 'Docs' || count($gvSelection) > 1 || !isset($_POST['selectedObjs']) || !is_array($_POST['selectedObjs']) || count($_POST['selectedObjs']) !== count($gvSelection) || !isset($_POST['selectedObjTypes']) || !is_array($_POST['selectedObjTypes']) || count($_POST['selectedObjTypes']) !== count($gvSelection) || !in_array($_POST['selectedObjTypes'][0], array('doc', 'folder')) || !isset($_POST['newName'])) {
         throw new CHttpException(400, Yii::t('app', 'Bad Request'));
     }
     $selectedObjId = array_pop($_POST['selectedObjs']);
     $type = array_pop($_POST['selectedObjTypes']);
     $newName = $_POST['newName'];
     if ($type === 'doc') {
         $obj = Docs::model()->findByPk($selectedObjId);
     } else {
         // $type === 'folder'
         $obj = DocFolders::model()->findByPk($selectedObjId);
     }
     if (!$obj) {
         self::$errorFlashes[] = Yii::t('app', 'Selected {type} does not exist', array('{type}' => $type === 'doc' ? ucfirst($type) : $type));
         return 0;
     }
     if (!Yii::app()->controller->checkPermissions($obj, 'edit')) {
         self::$errorFlashes[] = Yii::t('app', 'You do not have permission to edit this {type}.', array('{type}' => $type === 'doc' ? ucfirst($type) : $type));
         return 0;
     }
     if ($type === 'doc' && !Yii::app()->params->isAdmin && !in_array('name', Docs::model()->getEditableAttributeNames())) {
         self::$errorFlashes[] = Yii::t('app', 'You do not have permission to rename Docs.');
         return 0;
     }
     $obj->name = $newName;
     $successes = 0;
     if ($obj->save(true, array('name'))) {
         self::$successFlashes[] = Yii::t('app', 'Renamed {type}', array('{type}' => $type === 'doc' ? ucfirst($type) : $type));
         $successes = 1;
     } else {
         self::$errorFlashes[] = Yii::t('app', 'Failed to renamed {type}', array('{type}' => $type === 'doc' ? ucfirst($type) : $type));
     }
     return $successes;
 }
示例#27
0
文件: main.php 项目: shuvro35/X2CRM
    $authItem = $auth->getAuthItem($action);
    $permission = Yii::app()->params->isAdmin || Yii::app()->user->checkAccess($action) || is_null($authItem);
    if ($file->exists) {
        if ($permission) {
            $menuItems[$key] = array('label' => Yii::t('app', $value), 'itemOptions' => array('class' => 'top-bar-module-link'), 'url' => array("/{$key}/{$defaultAction}"), 'active' => strtolower($module) == strtolower($key) ? true : null);
        }
    } elseif (is_dir('protected/modules/' . $key)) {
        if (!is_null($this->getModule())) {
            $module = $this->getModule()->id;
        }
        if ($permission) {
            $active = strtolower($module) == strtolower($key) && (!isset($_GET['static']) || $_GET['static'] != 'true') ? true : null;
            $menuItems[$key] = array('label' => Yii::t('app', $value), 'url' => array("/{$key}/{$defaultAction}"), 'itemOptions' => array('class' => 'top-bar-module-link'), 'active' => $active);
        }
    } else {
        $page = Docs::model()->findByAttributes(array('name' => ucfirst(mb_ereg_replace('&#58;', ':', $value))));
        if (isset($page) && Yii::app()->user->checkAccess('DocsView')) {
            $id = $page->id;
            $menuItems[$key] = array('label' => ucfirst($value), 'url' => array('/docs/' . $id . '?static=true'), 'itemOptions' => array('class' => 'top-bar-module-link'), 'active' => Yii::app()->request->requestUri == $scriptUrl . '/docs/' . $id . '?static=true' ? true : null);
        }
    }
}
$maxMenuItems = 4;
//check if menu has too many items to fit nicely
$menuItemCount = count($menuItems);
if ($menuItemCount > $maxMenuItems) {
    end($menuItems);
    //move the last few menu items into the "More" dropdown
    for ($i = 0; $i < $menuItemCount - ($maxMenuItems - 1); $i++) {
        $menuItems[key($menuItems)]['itemOptions'] = array('style' => 'display: none;', 'class' => 'top-bar-module-link');
        prev($menuItems);
示例#28
0
	private function globalExport() {
		
		$file='file.csv';
		$fp = fopen($file, 'w+');
		
		$users=UserChild::model()->findAll();
		$contacts=ContactChild::model()->findAll();
		$actions=ActionChild::model()->findAll();
		$sales=SaleChild::model()->findAll();
		$accounts=AccountChild::model()->findAll();
		$docs=Docs::model()->findAll();
		$profiles=Profile::model()->findAll();
		
		fputcsv($fp,array("0.9.1"));
		
		$userList=array();
		foreach($users as $user) {
			$userList[]=$user->attributes;
		}
		foreach ($userList as $fields) {
			unset($fields['id']);
			unset($fields['updatePassword']);
			$fields[]='user';
			fputcsv($fp, $fields);
			
		}
		
	
		$contactList=array();
		foreach($contacts as $contact) {
			$contactList[]=$contact->attributes;
		}
		foreach ($contactList as $fields) {
			unset($fields['id']);
			$fields[]='contact';
			fputcsv($fp, $fields);
			
		}
		
		$actionList=array();
		foreach($actions as $action) {
			$actionList[]=$action->attributes;
		}
		foreach ($actionList as $fields) {
			unset($fields['id']);
			$fields[]='action';
			fputcsv($fp, $fields);
			
		}
		
		$saleList=array();
		foreach($sales as $sale) {
			$saleList[]=$sale->attributes;
		}
		foreach ($saleList as $fields) {
			unset($fields['id']);
			$fields[]='sale';
			fputcsv($fp, $fields);
			
		}
		
		$accountList=array();
		foreach($accounts as $account) {
			$accountList[]=$account->attributes;
		}
		foreach ($accountList as $fields) {
			unset($fields['id']);
			$fields[]='account';
			fputcsv($fp, $fields);
			
		}
		
		$docList=array();
		foreach($docs as $doc) {
			$docList[]=$doc->attributes;
		}
		foreach ($docList as $fields) {
			unset($fields['id']);
			$fields[]='doc';
			fputcsv($fp, $fields);
			
		}
		
		$profileList=array();
		foreach($profiles as $profile) {
			if($profile->username!='admin')
				$profileList[]=$profile->attributes;
		}
		foreach ($profileList as $fields) {
			unset($fields['id']);
			unset($fields['avatar']);
			$fields[]='profile';
			fputcsv($fp, $fields);
			
		}


		fclose($fp);

	}
示例#29
0
 /**
  * Fix email templates broken by the 5.1->5.2/5.3 media module changes.
  */
 public function actionConvertEmailTemplates()
 {
     $status = null;
     if (isset($_POST['yt0'])) {
         $docs = Docs::model()->findAllByAttributes(array('type' => 'email'));
         $converted = 0;
         foreach ($docs as $doc) {
             $changed = false;
             preg_match_all('|<img(.*?)src="(.*?)"(.*?)/?>|ism', $doc->text, $matches);
             $serverBasePath = Yii::app()->request->getServerName() . Yii::app()->baseUrl;
             foreach ($matches[2] as $filePath) {
                 if (strpos($filePath, $serverBasePath) !== false) {
                     $uploadPath = str_replace($serverBasePath, '', $filePath);
                     $pieces = explode('/', $uploadPath);
                     $fileName = $pieces[sizeof($pieces) - 1];
                     $mediaObj = Media::model()->findByAttributes(array('fileName' => $fileName));
                     if (isset($mediaObj)) {
                         $doc->text = preg_replace('|<img(.*?)src="' . preg_quote($filePath) . '"(.*?)/?>|ism', '<img\\1src="' . $mediaObj->getPublicUrl() . '"\\2/>', $doc->text);
                         $changed = true;
                     }
                 }
             }
             if ($changed) {
                 $doc->save();
                 $converted++;
             }
         }
         $status = $converted;
     }
     $this->render('convertEmailTemplates', array('status' => $status));
 }
示例#30
0
 /**
  * Generate presentation markup for the quote.
  *
  * @param integer $id ID of the quote for which to create a presentation
  * @param bool $email Parameter passed to the item table markup generator
  * @param string $header Optional header to pass to the print view
  * @return type
  */
 public function getPrintQuote($id = null, $email = false)
 {
     $this->throwOnNullModel = false;
     $model = $this->getModel($id);
     if ($model == null) {
         return Yii::t('quotes', 'Quote {id} does not exist. It may have been deleted.', array('{id}' => $id));
     }
     if (!$model->templateModel instanceof Docs) {
         // Legacy view (very, very plain!)
         return $this->renderPartial('print', array('model' => $model, 'email' => $email), true);
     } else {
         // User-defined template
         $template = $model->templateModel;
         if (!$template instanceof Docs) {
             // Template not found (it was probably deleted).
             // Use the default quotes view.
             $model->template = null;
             $model->update(array('template'));
             return $this->getPrintQuote($model->id);
         }
         return Docs::replaceVariables($template->text, $model);
     }
 }