<?php  return array (
  'resourceClass' => 'modDocument',
  'resource' => 
  array (
    'id' => 28,
    'type' => 'document',
    'contentType' => 'text/html',
    'pagetitle' => 'ajax',
    'longtitle' => '',
    'description' => '',
    'alias' => '',
    'link_attributes' => '',
    'published' => 1,
    'pub_date' => 0,
    'unpub_date' => 0,
    'parent' => 12,
    'isfolder' => 0,
    'introtext' => '',
    'content' => '[[!fem.trosk.ajax]]',
    'richtext' => 0,
    'template' => 0,
    'menuindex' => 0,
    'searchable' => 1,
    'cacheable' => 1,
    'createdby' => 1,
    'createdon' => 1318681858,
    'editedby' => 1,
    'editedon' => 1318681920,
    'deleted' => 0,
    'deletedon' => 0,
    'deletedby' => 0,
    'publishedon' => 1318681800,
    'publishedby' => 1,
    'menutitle' => '',
    'donthit' => 0,
    'privateweb' => 0,
    'privatemgr' => 0,
    'content_dispo' => 0,
    'hidemenu' => 0,
    'class_key' => 'modDocument',
    'context_key' => 'web',
    'content_type' => 1,
    'uri' => '',
    'uri_override' => 0,
    '_content' => '[[!fem.trosk.ajax]]',
    '_isForward' => false,
  ),
  'contentType' => 
  array (
    'id' => 1,
    'name' => 'HTML',
    'description' => 'HTML content',
    'mime_type' => 'text/html',
    'file_extensions' => '.html',
    'headers' => NULL,
    'binary' => 0,
  ),
  'policyCache' => 
  array (
  ),
  'sourceCache' => 
  array (
    'modChunk' => 
    array (
      'fem.trosk.savedStavka' => 
      array (
        'fields' => 
        array (
          'id' => 26,
          'name' => 'fem.trosk.savedStavka',
          'description' => 'Chunk',
          'editor_type' => 0,
          'category' => 3,
          'cache_type' => 0,
          'snippet' => '<div class="savedStavka">
<p>[[+saved_item]]</p>
<p>[[+mjjed]] - [[+amount]]</p>
<span class="ed"><a href="#" id="[[+id]]" class="delete" name="[[+project_id]]">Obriši</a> <a href="[[+editUrl]]">Izmijeni</a></span>
</div>',
          'locked' => false,
          'properties' => 
          array (
          ),
        ),
        'policies' => 
        array (
          'web' => 
          array (
          ),
        ),
      ),
    ),
    'modSnippet' => 
    array (
      'fem.trosk.ajax' => 
      array (
        'fields' => 
        array (
          'id' => 36,
          'name' => 'fem.trosk.ajax',
          'description' => '',
          'editor_type' => 0,
          'category' => 3,
          'cache_type' => 0,
          'snippet' => '$ctxs = !empty($ctxs) ? $ctxs : $modx->context->get(\'key\');
if (!is_array($ctxs)) $ctxs = explode(\',\',$ctxs);

if (!$modx->user->hasSessionContext($ctxs)) {
	$data[\'message\']=\'Error user is messing something log\';
	return json_encode($data);
}
$trosk = $modx->getService(\'trosk\',\'Trosk\',$modx->getOption(\'doodles.core_path\',null,$modx->getOption(\'core_path\').\'components/trosk/\').\'model/trosk/\',$scriptProperties);
if (!($trosk instanceof Trosk)) return \'\';

$projectId=$_REQUEST[\'proj_id\'];
if(!empty($projectId)){
	$project=$modx->getObject(\'projects\',$projectId);
	if($modx->user->id!=$project->createdby){
		$data[\'message\']=\'Error user is messing something proj\';
		return json_encode($data);
	}
	$editId=$_REQUEST[\'edit_id\'];
	if(!empty($editId)){
		$item=$modx->getObject(\'items\',$editId);
		if($item->project_id!=$project->id){
			$data[\'message\']=\'Error user is messing something proj\';
			return json_encode($data);
		}
	}
}
	
$action=$_REQUEST[\'action\'];

switch ($action){
	case \'save_stavka\':
		$originalId = $_POST[\'original_id\'];
		$projectId = $_POST[\'project_id\'];
		$mjjed = $_POST[\'mjjed\'];
		$amount = $_POST[\'amount\'];
		$stavkaData=array(
			\'originalId\'=>$originalId,
			\'projectId\'=>$projectId,
			\'mjjed\'=>$mjjed,
			\'amount\'=>$amount,
		);
		if(empty($originalId) or empty($projectId) or empty($amount)or empty($mjjed)){
			$data[\'message\']=\'Popunite sva polja\';
			return json_encode($data);
		} 
		if($mjjed==\'odaberi\'){
			$data[\'message\']=\'Popunite sva polja\';
			return json_encode($data);
		}
		/*
		for ($i = 0; $i < 200; $i++) {
			$data[\'message\']=$trosk->saveStavka($stavkaData);
		}
		*/
		$data[\'message\']=$trosk->saveStavka($stavkaData);
		$data[\'lastn\']=$trosk->lastNSaved($projectId,3);
		return json_encode($data);
		break;
	case \'update_stavka\':
		$originalId = $_POST[\'original_id\'];
		$projectId = $_POST[\'project_id\'];
		$editId = $_POST[\'edit_id\'];
		$mjjed = $_POST[\'mjjed\'];
		$amount = $_POST[\'amount\'];
		$stavkaData=array(
			\'originalId\'=>$originalId,
			\'projectId\'=>$projectId,
			\'mjjed\'=>$mjjed,
			\'amount\'=>$amount,
		);
		if(empty($originalId) or empty($projectId) or empty($amount)or empty($mjjed)){
			$data[\'message\']=\'Popunite sva polja\';
			return json_encode($data);
		} 
		if($mjjed==\'odaberi\'){
			$data[\'message\']=\'Popunite sva polja\';
			return json_encode($data);
		}
		$data[\'message\']=$trosk->updateStavka($stavkaData,$editId);
		$data[\'lastn\']=$trosk->lastNSaved($projectId,3);
		return json_encode($data);
		break;
	case \'delete_stavka\':
		$stavkaId=$_POST[\'stav_id\'];
		$projectId = $_POST[\'proj_id\'];
		if(empty($stavkaId) or empty($projectId)){
			$data[\'message\']=\'Error\';
			return json_encode($data);
		}
		$data[\'message\']=$trosk->stavkaDelete($stavkaId);
		$data[\'lastn\']=$trosk->lastNSaved($projectId,3);
		return json_encode($data);
		break;
	default:
		break;
}
exit();',
          'locked' => false,
          'properties' => NULL,
          'moduleguid' => '',
        ),
        'policies' => 
        array (
          'web' => 
          array (
          ),
        ),
      ),
    ),
    'modTemplateVar' => 
    array (
    ),
  ),
);