Example #1
0
 public function getItemStatus()
 {
     $status = array();
     $c = new Criteria();
     $c->add(ColItemPeer::CATALOG_ID, $this->getCatalogId(), Criteria::EQUAL);
     $status[0] = ColItemPeer::doCount($c);
     $c->add(ColItemPeer::COL_STATUS_ID, ColStatus::AVAILABLE, Criteria::EQUAL);
     $status[1] = ColItemPeer::doCount($c);
     $c->remove(ColItemPeer::COL_STATUS_ID);
     $c->add(ColItemPeer::COL_STATUS_ID, ColStatus::READ, Criteria::EQUAL);
     $status[2] = ColItemPeer::doCount($c);
     $c->remove(ColItemPeer::COL_STATUS_ID);
     $c->add(ColItemPeer::COL_STATUS_ID, ColStatus::LOAN, Criteria::EQUAL);
     $status[3] = ColItemPeer::doCount($c);
     return $status;
 }
Example #2
0
 public function executeDoOrder()
 {
     $return_module = $this->getRequestParameter('return_module');
     $return_action = $this->getRequestParameter('return_action');
     $col_item_id = $this->getRequestParameter('id');
     $col_item = ColItemPeer::retrieveByPK($col_item_id);
     $this->forward404Unless($col_item);
     $col_item->setColStatusId($this->getRequestParameter('col_status_id'));
     $col_item->setColConditionId($this->getRequestParameter('col_condition_id'));
     $col_item->setCallNo($this->getRequestParameter('call_no'));
     $col_item->setIndexNo($this->getRequestParameter('index_no'));
     $col_item->setColLocationId($this->getRequestParameter('col_location_id'));
     $col_item->setColSourceId($this->getRequestParameter('col_source_id'));
     $col_item->setColSourceDesc($this->getRequestParameter('col_source_desc'));
     $col_item->setYearAdded($this->getRequestParameter('year_added'));
     $col_item->save();
     $this->forward($return_module, $return_action);
 }
Example #3
0
 public function getColItem($con = null)
 {
     include_once 'lib/model/om/BaseColItemPeer.php';
     if ($this->aColItem === null && $this->col_item_id !== null) {
         $this->aColItem = ColItemPeer::retrieveByPK($this->col_item_id, $con);
     }
     return $this->aColItem;
 }
Example #4
0
    foreach ($temp_table as $temp) {
        ?>
                                    <tr class="list<?php 
        ++$i;
        if ($i % 2 == 0) {
            echo ' even';
        }
        ?>
">
                                            <td style="vertical-align: middle;"><?php 
        echo $i;
        ?>
</td>
                                            <td style="vertical-align: middle;">
                                                <?php 
        $col_item = ColItemPeer::retrieveByPK($temp->getCounselingId());
        echo $col_item ? $col_item->getCatalog() && $col_item->getCatalog()->getCode() ? $col_item->getCatalog()->getCode() : '-' : '-';
        ?>
                                            </td>
                                            <td style="vertical-align: middle;"><?php 
        echo $col_item ? $col_item->getIndexNo() ? $col_item->getIndexNo() : '-' : '-';
        ?>
</td>
                                            <td style="vertical-align: middle;"><?php 
        echo $col_item ? $col_item->getCatalog() && $col_item->getCatalog()->getTitle() ? $col_item->getCatalog()->getTitle() : '-' : '-';
        ?>
</td>
                                            <td style="vertical-align: middle;"><?php 
        echo $col_item ? $col_item->getCatalog() && $col_item->getCatalog()->getCatCategory() ? $col_item->getCatalog()->getCatCategory()->toString() : '-' : '-';
        ?>
</td>
Example #5
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(ColItemPeer::ID, $pks, Criteria::IN);
         $objs = ColItemPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #6
0
 public function addCopies($action)
 {
     $copies = $action->getRequestParameter('copies');
     if (is_numeric($copies)) {
         for ($i = 1; $i < $copies + 1; $i++) {
             $c = new Criteria();
             $c->add(ColItemPeer::CALL_NO, $this->getCode() . '-' . $i);
             $col_item = ColItemPeer::doSelectOne($c);
             if ($col_item) {
                 ++$copies;
                 continue;
             } else {
                 $ci = new ColItem();
                 $ci->setCatalog($this);
                 $ci->setCallNo($this->getCode());
                 $ci->setIndexNo($this->getCode() . '-' . $i);
                 $ci->setColConditionId(1);
                 $ci->setColStatusId(1);
                 $ci->save();
             }
         }
     }
     $this->save();
 }
Example #7
0
							</tr>
							<?php 
}
?>

                           <tr class='fo_cat_title_cont'>
								<td style="width: 18%; text-align: left;"><label><?php 
echo __('Copies');
?>
</label></td>
								<td style="width: 2%; text-align:center;">:</td> 
                                <td style="width: 80%; text-align: left;">
                                <?php 
$c = new Criteria();
$c->add(ColItemPeer::CATALOG_ID, $catalog->getId());
$copies = ColItemPeer::doCount($c);
echo $copies . ' &nbsp;eksemplar';
?>
                                </td>
							</tr>
                            <tr class='fo_cat_title_cont_odd'>
								<td style="width: 18%; text-align: left;"><label><?php 
echo __('Available');
?>
</label></td>
								<td style="width: 2%; text-align:center;">:</td> 
                                <td style="width: 80%; text-align: left;">
                                <?php 
$status = $catalog->getItemStatus();
echo $status[1] . ' &nbsp;eksemplar';
?>
Example #8
0
 public static function doSelectJoinAllExceptColStatus(Criteria $c, $con = null)
 {
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     CirHistoryPeer::addSelectColumns($c);
     $startcol2 = CirHistoryPeer::NUM_COLUMNS - CirHistoryPeer::NUM_LAZY_LOAD_COLUMNS + 1;
     ColItemPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + ColItemPeer::NUM_COLUMNS;
     MemberPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + MemberPeer::NUM_COLUMNS;
     $c->addJoin(CirHistoryPeer::COL_ITEM_ID, ColItemPeer::ID);
     $c->addJoin(CirHistoryPeer::MEMBER_ID, MemberPeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = CirHistoryPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         $omClass = ColItemPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj2 = new $cls();
         $obj2->hydrate($rs, $startcol2);
         $newObject = true;
         for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
             $temp_obj1 = $results[$j];
             $temp_obj2 = $temp_obj1->getColItem();
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addCirHistory($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj2->initCirHistorys();
             $obj2->addCirHistory($obj1);
         }
         $omClass = MemberPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj3 = new $cls();
         $obj3->hydrate($rs, $startcol3);
         $newObject = true;
         for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
             $temp_obj1 = $results[$j];
             $temp_obj3 = $temp_obj1->getMember();
             if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj3->addCirHistory($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj3->initCirHistorys();
             $obj3->addCirHistory($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
Example #9
0
 public function executeListHistory()
 {
     $this->can_add = 0;
     $this->can_edit = 0;
     $this->can_remove = 0;
     $item_id = $this->getRequestParameter('id');
     $col_item = ColItemPeer::retrieveByPK($item_id);
     $this->forward404Unless($col_item);
     $c = new Criteria();
     $c->add(CirHistoryPeer::COL_ITEM_ID, $item_id);
     $this->sortLate($c);
     if ($this->getRequest()->hasParameter('filters')) {
         $filters = $this->getRequestParameter('filters');
         if (trim($this->getRequestParameter('member_name')) == '') {
             $filters['member_id'] = '';
         }
         if ($filters == 'clear') {
             $this->filters = null;
         } else {
             $defined_filter = false;
             foreach ($filters as $f) {
                 if (is_array($f)) {
                     if (strlen($f['from']) > 0 || strlen($f['to']) > 0) {
                         $defined_filter = true;
                         break;
                     }
                 } else {
                     if ($f != null && $f != '') {
                         $defined_filter = true;
                         break;
                     }
                 }
             }
             if ($defined_filter) {
                 $this->filters = $filters;
                 $this->filterLate($c, $this->getRequestParameter('filters'));
             }
         }
     }
     $rpp = $this->getRequestParameter('max_per_page', $this->getUser()->getAttribute('max_per_page', ParamsPeer::retrieveByCode('row_per_page')->getValue(), 'cir_history_list_late'));
     $this->getUser()->setAttribute('max_per_page', $rpp, 'cir_history_list_late');
     $pager = new sfPropelPager('CirHistory', $rpp);
     $pager->setCriteria($c);
     $page = $this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'cir_history_list_late'));
     $this->getUser()->setAttribute('page', $page, 'cir_history_list_late');
     $pager->setPage($page);
     $pager->init();
     $this->pager = $pager;
     $this->subtitle = $col_item->toString() . ' - ' . $col_item->getCatalog()->getTitle();
     $actions = array();
     $this->actions = $actions;
     $this->item_id = $item_id;
     $this->col_item = $col_item;
     $actions2 = array(array('name' => '<span>Riwayat Peminjaman</span>', 'url' => 'rpt_management/listHistory?id=' . $col_item->getId(), 'color' => 'sky', 'type' => 'direct'));
     array_unshift($actions2, array('name' => '<span>Sirkulasi Koleksi</span>', 'url' => "rpt_management/listDetail", 'color' => 'sun'));
     $this->actions2 = $actions2;
 }
Example #10
0
 public function executeDeleteItem()
 {
     $col_item = ColItemPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($col_item);
     $col_item->delete();
     return $this->redirect('collection/listItem?catalog_id=' . $this->getRequestParameter('catalog_id'));
 }
Example #11
0
 public function executePrintCard()
 {
     $id = $this->getRequestParameter('id');
     $col_item = ColItemPeer::retrieveByPK($id);
     $this->forward404Unless($col_item);
     $this->col_item = $col_item;
 }
Example #12
0
 public function executeList2()
 {
     $this->can_add = 0;
     $this->can_edit = 0;
     $this->can_remove = 0;
     $col_item = ColItemPeer::retrieveByPk($this->getRequestParameter('col_item_id'));
     $member = MemberPeer::retrieveByPk($this->getRequestParameter('member_id'));
     $this->forward404Unless($col_item || $member);
     $c = new Criteria();
     if ($col_item) {
         $c->add(VCirHistoryMemberPeer::COL_ITEM_ID, $col_item->getId());
     }
     if ($member) {
         $c->add(VCirHistoryMemberPeer::MEMBER_ID, $member->getId());
     }
     $this->sort($c);
     if ($this->getRequest()->hasParameter('filters')) {
         $filters = $this->getRequestParameter('filters');
         if ($filters == 'clear') {
             $this->filters = null;
         } else {
             $defined_filter = false;
             foreach ($filters as $f) {
                 if (is_array($f)) {
                     if (strlen($f['from']) > 0 || strlen($f['to']) > 0) {
                         $defined_filter = true;
                         break;
                     }
                 } else {
                     if ($f != null && $f != '') {
                         $defined_filter = true;
                         break;
                     }
                 }
             }
             if ($defined_filter) {
                 $this->filters = $filters;
                 $this->filter($c, $this->getRequestParameter('filters'));
             }
         }
     }
     $rpp = $this->getRequestParameter('max_per_page', $this->getUser()->getAttribute('max_per_page', ParamsPeer::retrieveByCode('row_per_page')->getValue(), 'cir_history'));
     $this->getUser()->setAttribute('max_per_page', $rpp, 'cir_history');
     $pager = new sfPropelPager('VCirHistoryMember', $rpp);
     $pager->setCriteria($c);
     $page = $this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'cir_history'));
     $this->getUser()->setAttribute('page', $page, 'cir_history');
     $pager->setPage($this->getRequestParameter('page', 1));
     $pager->init();
     $this->pager = $pager;
     $this->col_item = $col_item;
     $this->member = $member;
     $this->col_item_id = $this->getRequestParameter('col_item_id');
     $this->member_id = $this->getRequestParameter('member_id');
 }
Example #13
0
 public function executeDoOrder()
 {
     $return_module = $this->getRequestParameter('return_module');
     $return_action = $this->getRequestParameter('return_action');
     $member_id = $this->getRequestParameter('member_id');
     $col_item_id = $this->getRequestParameter('id');
     $order_type = $this->getRequestParameter('order_type');
     $length = $this->getRequestParameter('length');
     $c = new Criteria();
     $c->add(ColStatusPeer::CODE, $order_type, Criteria::EQUAL);
     $col_status = ColStatusPeer::doSelectOne($c);
     $col_item = ColItemPeer::retrieveByPK($col_item_id);
     $this->forward404Unless($member_id && $col_item && $col_status);
     $col_item->setColStatus($col_status);
     $now = time();
     if ($order_type == 'available') {
         $col_item->setMemberId(null);
         $col_item->setColConditionId($this->getRequestParameter('col_condition_id'));
         $c = new Criteria();
         $c->add(CirHistoryPeer::MEMBER_ID, $member_id);
         $c->add(CirHistoryPeer::COL_ITEM_ID, $col_item_id);
         $c->add(CirHistoryPeer::RETURN_DATE, null);
         $cir_hist = CirHistoryPeer::doSelectOne($c);
         $cir_hist->setReturnDate(date('Y-m-d H:i:s', $now));
         $cir_hist->setReturnNote($this->getRequestParameter('return_note'));
         $cir_hist->setFine($this->getRequestParameter('fine'));
         $cir_hist->setMiscFine($this->getRequestParameter('misc_fine'));
         $cir_hist->save();
     } else {
         $col_item->setMemberId($member_id);
         $cir_hist = new CirHistory();
         $cir_hist->setColItem($col_item);
         $cir_hist->setMemberId($member_id);
         $cir_hist->setColStatus($col_status);
         $cir_hist->setOrderDate(date('Y-m-d H:i:s', $now));
         $cir_hist->setOrderNote($this->getRequestParameter('order_note'));
         if (!$length || $length != null) {
             $cir_hist->setDueDate(date('Y-m-d H:i:s', $length * 60 * 60 * 24 + $now));
         } else {
             $cir_hist->setDueDate(date('Y-m-d H:i:s', $cir_hist->getRegulation()->getLoanLength() * 60 * 60 * 24 + $now));
         }
         $cir_hist->save();
     }
     $col_item->save();
     $this->forward($return_module, $return_action);
 }
Example #14
0
 public function executeDelete()
 {
     $catalog = CatalogPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($catalog);
     $c = new Criteria();
     $c->add(CatalogEmployeePeer::CATALOG_ID, $catalog->getId());
     $ce = CatalogEmployeePeer::doSelectOne($c);
     $cw = new Criteria();
     $cw->add(ColItemPeer::CATALOG_ID, $catalog->getId());
     $ci = ColItemPeer::doSelectOne($cw);
     $ce->delete();
     $ci->delete();
     $catalog->delete();
     return $this->redirect('employee_bank/list');
 }
Example #15
0
 public function executeReturnOrder()
 {
     $this->returnModule = 'visitor_list';
     $this->returnAction = 'return';
     $this->_title = 'ReturnOrder';
     $this->item = ColItemPeer::retrieveByPK($this->getRequestParameter('id'));
     $c = new Criteria();
     $c->add(CirHistoryPeer::COL_ITEM_ID, $this->item->getId());
     $c->add(CirHistoryPeer::RETURN_DATE, null);
     $cir_hist = CirHistoryPeer::doSelectOne($c);
     $this->member = $cir_hist->getMember();
     $this->max_loan_limit = false;
     $this->forward404Unless($this->item);
     $this->setTemplate('order');
 }
Example #16
0
 public function executeGetLabel()
 {
     $col_item = ColItemPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($col_item);
     $this->col_item = $col_item;
     define('IMG_FORMAT_PNG', 1);
     define('IMG_FORMAT_JPEG', 2);
     define('IMG_FORMAT_WBMP', 4);
     define('IMG_FORMAT_GIF', 8);
     require 'FColor.php';
     require 'BarCode.php';
     require 'FDrawing.php';
     include 'code128.barcode.php';
     $color_black = new FColor(0, 0, 0);
     $color_white = new FColor(255, 255, 255);
     $code_generated = new code128(32, $color_black, $color_white, 1, $col_item->toString(), 3);
     $drawing = new FDrawing(1024, 1024, '', $color_white);
     $drawing->init();
     $drawing->add_barcode($code_generated);
     $drawing->draw_all();
     $im = $drawing->get_im();
     $im2 = imagecreate($code_generated->lastX, $code_generated->lastY);
     imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY);
     $drawing->set_im($im2);
     $drawing->finish(IMG_FORMAT_PNG);
 }
Example #17
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ColItemPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCatalogId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setColStatusId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setColConditionId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setMemberId($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setColLocationId($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setColSourceId($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setColSourceDesc($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setYearAdded($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setIndexNo($arr[$keys[9]]);
     }
 }
        echo $cat_category->getName() ? $cat_category->toString() : '-';
        ?>
</td>
			<td align="left">
			<?php 
        $c = new Criteria();
        $c->add(CatalogPeer::CAT_CATEGORY_ID, $cat_category->getId());
        $count_title = CatalogPeer::doCount($c);
        echo $count_title > 0 ? $count_title : '-';
        ?>
			</td>
            		<td align="left">
			<?php 
        $cw = new Criteria();
        $cw->add(CatalogPeer::CAT_CATEGORY_ID, $cat_category->getId());
        $cw->addJoin(ColItemPeer::CATALOG_ID, CatalogPeer::ID);
        $count_copies = ColItemPeer::doCount($cw);
        echo $count_copies > 0 ? $count_copies : '-';
        ?>
			</td>
		</tr>
		<?php 
    }
    ?>
	<?php 
}
?>
	</tbody>
</table>
</center>
Example #19
0
 public function executeGetItem()
 {
     $id = $this->getRequestParameter('id');
     $this->forward404Unless($id);
     $c = new Criteria();
     $c->add(ColItemPeer::CATALOG_ID, $id);
     $c->addAscendingOrderByColumn(ColItemPeer::INDEX_NO);
     $this->rows = ColItemPeer::doSelect($c);
 }
Example #20
0
 public function getColItemsJoinColSource($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BaseColItemPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collColItems === null) {
         if ($this->isNew()) {
             $this->collColItems = array();
         } else {
             $criteria->add(ColItemPeer::CATALOG_ID, $this->getId());
             $this->collColItems = ColItemPeer::doSelectJoinColSource($criteria, $con);
         }
     } else {
         $criteria->add(ColItemPeer::CATALOG_ID, $this->getId());
         if (!isset($this->lastColItemCriteria) || !$this->lastColItemCriteria->equals($criteria)) {
             $this->collColItems = ColItemPeer::doSelectJoinColSource($criteria, $con);
         }
     }
     $this->lastColItemCriteria = $criteria;
     return $this->collColItems;
 }
Example #21
0
 public static function doSelectFiltered(Criteria $criteria, $con = null)
 {
     return ColItemPeer::doSelect($criteria);
 }
Example #22
0
					</td>
                    <td class='filter'>
		    			<?php 
echo input_tag('filters[CODE]', isset($filters['CODE']) ? $filters['CODE'] : null, array('size' => 12));
?>
		  			</td>
		 			<td class='filter'>
		    			<?php 
echo input_tag('filters[NAME]', isset($filters['NAME']) ? $filters['NAME'] : null, array('size' => 25));
?>
		 			</td>
					<td class='filter'>
					<?php 
echo input_hidden_tag('filters[COL_ITEM_ID]', isset($filters['COL_ITEM_ID']) ? $filters['COL_ITEM_ID'] : null);
if (isset($filters['COL_ITEM_ID']) && $filters['COL_ITEM_ID']) {
    echo input_auto_complete_tag('index', isset($filters['COL_ITEM_ID']) && $filters['COL_ITEM_ID'] ? ColItemPeer::retrieveByPk($filters['COL_ITEM_ID'])->getIndexNo() : '', '/col_item/getIndex', array('size' => 20), array('after_update_element' => 'function(f, s) {$("COL_ITEM_ID").updateFromInformalAutocomplete(f, s);}', 'min_chars' => 1));
} else {
    echo input_auto_complete_tag('index', null, '/col_item/getIndex', array('size' => 20), array('after_update_element' => 'function(f, s) {$("filters_COL_ITEM_ID").updateFromInformalAutocomplete(f, s);}', 'min_chars' => 1));
}
?>
						<?php 
#echo object_select_tag(isset($filters['col_item_id']) ? $filters['col_item_id'] : null, null, array ( 'include_blank' => true, 'related_class' => 'ColItem', 'text_method' => '__toString', 'control_name' => 'filters[col_item_id]', 'style'=>"width: 80px;", ))
?>
					</td>
					<!-- 
                    <td class='filter'>
						<?php 
#echo object_select_tag(isset($filters['col_status_id']) ? $filters['col_status_id'] : null, null, array ( 'include_blank' => true, 'related_class' => 'ColStatus', 'text_method' => '__toString', 'control_name' => 'filters[col_status_id]', ))
?>
					</td>
                    -->
Example #23
0
 public function executeSimpan()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_edit_i18n = $i18n->globalMessageFormat->format('edit');
     $action_type = $this->getRequestParameter('action_type');
     if ($action_type == $action_i18n || !$this->getRequestParameter('id', 0)) {
         $catalog = new Catalog();
     } else {
         $catalog = CatalogPeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($catalog);
     }
     $catalog->setId($this->getRequestParameter('id'));
     $catalog->setCatLanguageId(1);
     $catalog->setCatCategoryId(15);
     $catalog->setCatSubjectId(4202);
     $catalog->setTitle($this->getRequestParameter('title'));
     $catalog->setPublishedYear(2011);
     $catalog->setPublishedLocation('Jakarta');
     $catalog->setSynopsis($this->getRequestParameter('synopsis'));
     $catalog->setSearchKeywords($this->getRequestParameter('search_keywords'));
     $catalog->setPublisherId(8682);
     $catalog->save();
     $cw = new CatalogWriter();
     $cw->setCatalog($catalog);
     $cw->setWriterId(8112);
     $cw->save();
     $writer_name = $catalog->getFirstWriterName();
     $writer_name = preg_replace('/\\W+/', '', $writer_name);
     $writer_name = strtoupper(substr($writer_name, 0, 3));
     $title = substr(strtoupper(str_replace(' ', '', $catalog->getTitle())), 0, 3);
     $subject_code = $catalog->getCatSubject()->getCode();
     $catalog->setCode("{$subject_code}-{$writer_name}-{$title}");
     $catalog->save();
     if ($this->hasRequestParameter('copies') && $this->getRequestParameter('copies') > 0) {
         $catalog->addCopies($this);
     }
     $cover_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR;
     if ($this->hasRequestParameter('coverFile') && $this->getRequestParameter('coverFile') != '' && $this->getRequestParameter('coverFile') != null) {
         // get cover content
         $cover_file = $cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile');
         $content = file_get_contents($cover_file);
         $im = imagecreatefromstring($content);
         list($w, $h) = getimagesize($cover_file);
         // generate cover
         $cover = imagecreatetruecolor(150, 200);
         imagecopyresized($cover, $im, 0, 0, 0, 0, 150, 200, $w, $h);
         // generate thumbnail
         $thumb = imagecreatetruecolor(100, 150);
         imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 150, $w, $h);
         // get cover record
         $c = new Criteria();
         $c->add(CatalogCopiedPeer::CATALOG_ID, $catalog->getId());
         $catalog_cover = CatalogCopiedPeer::doSelectOne($c);
         if ($catalog_cover == null) {
             $catalog_cover = new CatalogCopied();
             $catalog_cover->setCatalog($catalog);
         }
         // save cover
         imagepng($cover, $cover_file);
         $catalog_cover->setCover(base64_encode(file_get_contents($cover_file)));
         imagepng($thumb, $cover_file);
         $catalog_cover->setThumbnail(base64_encode(file_get_contents($cover_file)));
         $catalog_cover->save();
         unlink($cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile'));
     }
     if ($this->hasRequestParameter('file') && $this->getRequestParameter('file') != '' && $this->getRequestParameter('file') != null) {
         $fileName = $this->getRequestParameter('file');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_1') && $this->getRequestParameter('file_1') != '' && $this->getRequestParameter('file_1') != null) {
         $fileName = $this->getRequestParameter('file_1');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_2') && $this->getRequestParameter('file_2') != '' && $this->getRequestParameter('file_2') != null) {
         $fileName = $this->getRequestParameter('file_2');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_3') && $this->getRequestParameter('file_3') != '' && $this->getRequestParameter('file_3') != null) {
         $fileName = $this->getRequestParameter('file_3');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_4') && $this->getRequestParameter('file_4') != '' && $this->getRequestParameter('file_4') != null) {
         $fileName = $this->getRequestParameter('file_4');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_5') && $this->getRequestParameter('file_5') != '' && $this->getRequestParameter('file_5') != null) {
         $fileName = $this->getRequestParameter('file_5');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_6') && $this->getRequestParameter('file_6') != '' && $this->getRequestParameter('file_6') != null) {
         $fileName = $this->getRequestParameter('file_6');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_7') && $this->getRequestParameter('file_7') != '' && $this->getRequestParameter('file_7') != null) {
         $fileName = $this->getRequestParameter('file_7');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_8') && $this->getRequestParameter('file_8') != '' && $this->getRequestParameter('file_8') != null) {
         $fileName = $this->getRequestParameter('file_8');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_9') && $this->getRequestParameter('file_9') != '' && $this->getRequestParameter('file_9') != null) {
         $fileName = $this->getRequestParameter('file_9');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     if ($this->hasRequestParameter('file_10') && $this->getRequestParameter('file_10') != '' && $this->getRequestParameter('file_10') != null) {
         $fileName = $this->getRequestParameter('file_10');
         $catalog_file = new CatalogFile();
         $catalog_file->setCatalog($catalog);
         $catalog_file->setFile($fileName);
         $catalog_file->save();
     }
     $dept_id = $this->getContext()->getUser()->getAttribute('department_id', null, 'bo');
     $dept = $this->getContext()->getUser()->getAttribute('department', null, 'bo');
     if ($dept_id == 2) {
         $c = new Criteria();
         $c->add(ColItemPeer::CATALOG_ID, $catalog->getId());
         $ci = ColItemPeer::doSelectOne($c);
         $ci->setColLocationId(102);
         $ci->save();
     } elseif ($dept_id == 3) {
         $c = new Criteria();
         $c->add(ColItemPeer::CATALOG_ID, $catalog->getId());
         $ci = ColItemPeer::doSelectOne($c);
         $ci->setColLocationId(103);
         $ci->save();
     } else {
         $c = new Criteria();
         $c->add(ColItemPeer::CATALOG_ID, $catalog->getId());
         $ci = ColItemPeer::doSelectOne($c);
         $ci->setColLocationId(104);
         $ci->save();
     }
     return $this->redirect('catalog/listBank');
 }