Tuesday, 10 September 2013

edit view without modifying file cakePHP

edit view without modifying file cakePHP

View(edit) is displaying all the fields correctly and updating modified
fields but it cant handle files. i.e., if new file is uploaded then it has
to be updated if not old file name has to be retained.
controller:
public function edit($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Student->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->Student->id = $id;
if ($this->Student->save($this->request->data)) {
$this->Session->setFlash(__('Your post has been updated.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to update your post.'));
}
if (!$this->request->data) {
$this->request->data = $post;
}
}
View:
<h1>Edit student record</h1>
<?php
echo $this->Form->create('Student',array('type'=>'file'));
echo $this->Form->input('first_name');
echo $this->Form->input('current_address');
echo 'resume'.$this->Form->file('resume');
echo $this->Form->input ('comments');
echo 'photo'.$this->Form->file('photo');
echo $this->Form->input('id', array('type' => 'hidden'));
//echo $this->Form->input('resume', array('type' => 'hidden'));
//echo $this->Form->input('photo', array('type' => 'hidden'));
echo $this->Form->end('Save Post');
Can someone suggest me how to handle the upload thing

How to extract conditional statements from linq query?

How to extract conditional statements from linq query?

I want to be able to extract conditional statements from following query
inside a function. It's a linq to EF query. How should i do that? is there
any alternative way so that object oriented principles be applied (like
open/closed)?
var query = new UvwRequestAssignmentManagementBO().GetAll().Where(uvw
=> (uvw.FK_ProcessStep == 2)
&& (uvw.FK_Entity == SecurityContext.Current.User.FK_Entity)
&& (uvw.FK_Manager == 15))
.Select(p => new ReqSupAdminGridVm()
{
NameFamily = p.NameFamily,
RequestDate = p.RequestDate,
RequestNo = p.RequestNo,
RequestType = p.RequestType == 1 ?"a"
: (p.RequestType == 2 ? "b"
: (p.RequestType == 3 ? "c" :
(p.RequestType == 4 ? "d" : ""))),
RequestEvaluationStatus =
p.RequestEvaluationStatus_Aggregation == 1 ? "a"
:
(p.RequestEvaluationStatus_Aggregation
== 2 ? "b"
:
(p.RequestEvaluationStatus_Aggregation
== 3 ?"c"
:(p.RequestEvaluationStatus_Aggregation
== 4 ? "d" : ""))),
});
For Example instead of writing :
RequestType = p.RequestType == 1 ?"a"
: (p.RequestType == 2 ? "b"
: (p.RequestType == 3 ? "c" :
(p.RequestType == 4 ? "d" : ""))),
i want to be able to write this inside another class :
RequestType = ReqType.GetReqType(p.RequestType);
string GetReqType(int type){
switch(type){
case 1:
return "a";
case 2:
return "b";
}
}

Monday, 9 September 2013

Adding Columns in PHP

Adding Columns in PHP

I am trying to add columns together to get a total at the end of each
column, I searched this topic and tried to do what it said but got the an
error "You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'SELECT SUM(Sea) FROM PlayerStats; FROM SeasonStats WHERE
SeasonStats.PlayerID=' at line 2" I am pretty new at this and cannot seem
to figure out how to make it work. Any help would be greatly appreciated.
$oPlayerStats = mysql_query("
SELECT SeasonStats.Sea, SeasonStats.Team, SeasonStats.GP,
SeasonStats.Goals, SeasonStats.Assists, SeasonStats.Points,
SeasonStats.PlusMinus, SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH,
SeasonStats.GW, SeasonStats.GT, SeasonStats.S
SELECT SUM(Sea) FROM PlayerStats;
FROM SeasonStats
WHERE SeasonStats.PlayerID=$iPlayerID
ORDER BY SeasonStats.Sea;
") or die(mysql_error());
echo "<br><br><table border=1 cellpadding=1>";
echo "<tr>";
echo "<td>Season</td> ";
echo "<td>Team</td> ";
echo "<td>GP</td> ";
echo "<td>G</td> ";
echo "<td>A</td> ";
echo "<td>P</td> ";
echo "<td>PIM</td> ";
echo "<td>+/-</td> ";
echo "<td>PPG</td> ";
echo "<td>SHG</td> ";
echo "<td>GWG</td> ";
echo "<td>GTG</td> ";
echo "<td>Shots</td> ";
while($row = mysql_fetch_array($oPlayerStats))
{
echo "<tr>";
echo "<td>".$row['Sea']."</td> ";
echo "<td>".$row['Team']."</td> ";
echo "<td>".$row['GP']."</td> ";
echo "<td>".$row['Goals']."</td> ";
echo "<td>".$row['Assists']."</td> ";
echo "<td>".$row['Points']."</td> ";
echo "<td>".$row['Pim']."</td> ";
echo "<td>".$row['PlusMinus']."</td> ";
echo "<td>".$row['PP']."</td> ";
echo "<td>".$row['SH']."</td> ";
echo "<td>".$row['GW']."</td> ";
echo "<td>".$row['GT']."</td> ";
echo "<td>".$row['S']."</td> ";
$result = mysql_query('SELECT SUM(Sea) AS value_sum FROM codes');
$row = mysql_fetch_assoc($result);
$sum = $row['value_sum'];

How to post values from multiple drop down menus in the same form

How to post values from multiple drop down menus in the same form

I have a form with a unique identifier for each row in the form. in each
row I also have a drop down menu with user names.
basicly each row has a task and next to each task a drop down menu with
name of the task owner. what I need to do is to be able to POST the user
name along with their task id so I can update the owner of the task in one
submit.
so let say the following is what I have
ID Title MENU
1 Tast 1 (please select)
2 Tast 2 (please select)
3 Tast 3 (please select)
if the user selected "Mike" in row 1 then I want to update the database
with the Mike's ID which is Mike's option value in the drop down menu.
The thing that I am having a diffecuty with in trying to link each menu to
the correct row id "task id". this is how my menu code is displaied
<select name="user_id[]">
<option value="200">Mike</option>
<option value="205">Jaylen</option>
<option value="220"> Jack</option>
</select>
I want to be able to link each menu to the correct task id so when I post
the form I can link each menu to the correct row.
How can I include the task id in each menu?
Thanks

ON binding too much recursion

ON binding too much recursion

I am trying to bind a handler on a UL to detect when a div is clicked
inside LI and then trigger a hyperlink click event within the LI.
Note: I only want clicking .col2 to trigger the event.
I am getting too much recursion error because the click event of the
hyperlink is trigger the click event on the UL
I have tried stopPropagation but it doesnt seem to work, any ideas?
$('#ul_search').on('click', 'div.col2', MyClickHandler);
function MyClickHandler(e) {
e.stopPropagation();
var control = $(this);
control.find('a').click();
e.stopPropagation();
}
<ul id="ul_search">
<li>
<div class="col1">
Col1
</div>
<div class="col2">
Go to
<a href="http://www.google.com">Google</a>
by clicking here
</div>
</li>
<li>
<div class="col1">
Col1
</div>
<div class="col2">
Go to
<a href="http://www.yahoo.com">Yahoo</a>
by clicking here
</div>
</li>
</ul>

Query Construction: Count, Case, Datediff, and Group By

Query Construction: Count, Case, Datediff, and Group By

[Reframing prior question, which had been posed as a question about Cursors.]
I am looking for a way to select counts under certain date conditions.
Say there is a table, T1, with 2 fields (ID, Date). The ID is not a unique
key. The table records events by id, and some ids occur frequently, some
infrequently.
For example:
ID | Date
1 | 2010-01-01
2 | 2010-02-01
3 | 2010-02-15
2 | 2010-02-15
4 | 2010-03-01
I would like to create a new table with the following fields: ID, Date,
Count of times ID appears in 6 months previous to Date, Count of times ID
appears in 6 months after Date.
In essence, for every row in the existing table, I want to add a column
that looks back for times the same ID has appeared in previous six months,
and look ahead for times the same ID has appeared in following six months.
Is there a best way to formulate the appropriate query?

adding certificate policies extension in CSR

adding certificate policies extension in CSR

I am trying to add a "certificate policies" extension in CSR using openssl
(version 1.0.1.e).
1) Is the certificate requester allowed to deal with certificate policies
or only CA should do it?
2) Based on function mkreq() in file
openssl/demos/x509/openssl/demos/x509/mkreq.c, I added the following line:
add_ext(exts, NID_certificate_policies, "1.3.6.1");
Unfortunately it lead to a segmentation fault. Is the syntax correct? Any
clue what is wrong?
Thanks