Wayne,
I just worked out how to remove "not null" in the "information_doc"
entry in the DB, so that you dont have to attach a file.
But as I said previously I dont really know any thing about cakephp/
php.
How can I make the "Information" download link only appear if there is
a file uploaded for it, like so http://82.34.51.7/examp.png

I'm assuming (from my very limited knowledge) that I need to make
changes in these two files?

The following is the contents of the application_config.php

<?php

class JobsController extends AppController
{
    var $uses = array('Job', 'JobType');

    function beforeFilter()
    {
        if (substr($this->action, 0, 5) == 'admin')
        {
            $this->__checkSession();
        }
    }

    function index($jobTypeId = null)
    {
        $conditions = array();
        $conditions['AND'] = array('OR' =>
array('UNIX_TIMESTAMP(Job.expires) > UNIX_TIMESTAMP(NOW())',
'Job.expires IS NULL'));
        if (intval($jobTypeId) > 0)
        {
            array_push($conditions['AND'], "JobType.id =
'$jobTypeId'");
        }

        $this->set('jobTypes', $this->JobType->find('list',
array('id', 'name')));
        $this->set('currentJobType', $jobTypeId);
        $this->set('jobs', $this->Job->findAll($conditions, null,
'Job.expires DESC'));
    }

    function view($id = null)
    {
        if ($id == null)
        {
            $this->redirect('index');
        }
        $this->Job->id = $id;
        $job = $this->Job->read();
        if (empty($job))
        {
            $this->redirect('index');
        }
        $this->set('job', $job);
    }

    function admin_index()
    {
        $this->set('jobs', $this->Job->findAll(null, null,
'Job.expires DESC'));
    }

    function admin_add()
    {
        $this->set('job_types', $this->JobType->find('list',
array('id', 'name')));
        if (!empty($this->data))
        {
            // Handle the Application Pack uploads
            $this->data['Job']['application_form_doc'] = $this-
>__handleUpload($_FILES['application_form_doc']);
            $this->data['Job']['job_description_doc'] = $this-
>__handleUpload($_FILES['job_description_doc']);
            $this->data['Job']['information_doc'] = $this-
>__handleUpload($_FILES['information_doc']);

            if ($this->Job->save($this->data))
            {
                $this->flash('The job has been added successfully.',
'index');
            }
        }
    }

    function admin_edit($id = null)
    {
        $this->set('job_types', $this->JobType->find('list',
array('id', 'name')));
        if (!empty($this->data))
        {

            // Handle the Application Pack uploads
            $this->data['Job']['application_form_doc'] = $this-
>__handleUpload($_FILES['application_form_doc'],
                $this->data['Job']['__afdoc']);
            $this->data['Job']['job_description_doc'] = $this-
>__handleUpload($_FILES['job_description_doc'],
                $this->data['Job']['__jddoc']);
            $this->data['Job']['information_doc'] = $this-
>__handleUpload($_FILES['information_doc'],
                $this->data['Job']['__ifdoc']);

            // If the expiry date is empty, set it to null
            if (trim($this->data['Job']['expires']) == '')
            {
                // Update the job expires data to null in the DB
                $this->Job->query('UPDATE jobs SET jobs.expires = NULL
WHERE jobs.id = ' . $this->data['Job']['id']);
            }

            // Save the edit data
            if ($this->Job->save($this->data))
            {
                $this->flash('The job has been edited successfully.',
'index');
            }
        }
        else
        {
            if ($id == null)
            {
                $this->redirect('index');
            }
            $this->Job->id = $id;
            $job = $this->Job->read();
            if (empty($job))
            {
                $this->redirect('index');
            }
            $this->data = $job;
        }
    }

    function admin_delete($id = null)
    {
        $this->Job->id = $id;
        $this->Job->del();
        $this->flash('The job has been deleted successfully.',
'index');
    }

    function nonteaching()
    {
        $this->layout = 'application';
        $this->pageTitle = 'Non-Teaching Application Form';
    }

    function teaching()
    {
        $this->layout = 'application';
        $this->pageTitle = 'Teaching Application Form';
    }

    function confirmapplication()
    {
        $this->layout = 'application';
        $this->pageTitle = 'Confirm Application';
    }

    function sendapplication()
    {
        //$this->layout = 'plain';
        $htmlData = $_POST['appData'];
        $htmlData = '<html><head><title>Job Application</title></
head><body>' . $htmlData . '</body></html>';

        $mailHeaders = "From: " . MAIL_FROM . "\r\n";
        $mailHeaders .= "X-Mailer: Job Board 1.0";
        $mailHeaders .= "MIME-Version: 1.0\r\n";
        $mailHeaders .= "Content-type: text/html; charset=utf-8";

        @mail(MAIL_TO, 'New Job Application', $htmlData,
$mailHeaders);
        $this->flash('Thank you for submitting your job application.
Your application has been received and will be reviewed shortly. You
will now be redirected to the job index', 'index', 10);
    }

    function __handleUpload($fData, $tgtFilename = null)
    {
        // First assign the default target (in case this is an edit)
        $filename = $tgtFilename;

        // If a file is uploaded
        if (!empty($fData['tmp_name']))
        {
            // Generate a friendly filename
            $extIdx = intval(strrpos($fData['name'],
'.'));
            // Get the name of the original file without the extension
            $oldname = substr($fData['name'], 0, $extIdx);
            // Replace spaces on the oldname with dashes
            $newfilename = str_replace(' ', '-', $oldname);
            // Append the current date and time to the filename in the
format DDMMYY-HHMMSS
            $newfilename .= '_' . date('dmy-His');
            // Get the file extension
            $newfilename .= substr($fData['name'], $extIdx);

            // Remove the old file and write the new one
            $oldtarget = UPLOADS_PATH . "/$filename";
            $target = UPLOADS_PATH . "/$newfilename";
            // Remove the old target if it exists
            if (file_exists($oldtarget))
            {
                unlink($oldtarget);
            }
            // Assign the filename and save the new target
            $filename = $newfilename;
            copy($fData['tmp_name'], $target);
            unlink($fData['tmp_name']);
        }

        return $filename;
    }
}

?>


AND THE FOLLOWING IS THE view.ctp FILE


<div class="jobleftpane">
<h2><?php echo $job['Job']['title'] ?></h2>
<div class="content">
    <b>Closing Date: <?php echo empty($job['Job']['expires']) ? 'No
closing date specified' : date(DT_FORMAT, strtotime($job['Job']
['expires'])) ?></b>
    <div style="margin-top: 12px">
        <?php echo str_replace("\r\n", "<br />", $job['Job']
['description']) ?>
    </div>
</div>
</div>

<div class="jobrightpane">
    <fieldset>
        <legend>Salary</legend>
        <?php echo $job['Job']['salary'] ?>
    </fieldset>

    <fieldset>
        <legend>Hours</legend>
        <?php echo $job['Job']['hours'] ?>
    </fieldset>

    <fieldset>
        <legend>Qualifications Needed</legend>
        <?php echo $job['Job']['qualifications'] ?>
    </fieldset>

    <fieldset>
        <legend>Application Pack</legend>
        <?php echo $html->image('pdf-icon.gif', array('alt'=>'',
'style'=>'vertical-align: bottom; margin-right: 5px')) ?><?php echo
$html->link('Application Form', UPLOADS_URL . "/{$job['Job']
['application_form_doc']}", array('style'=>'color: #000; text-
decoration: none')); ?><br />
        <?php echo $html->image('pdf-icon.gif', array('alt'=>'',
'style'=>'vertical-align: bottom; margin-right: 5px')) ?><?php echo
$html->link('Job Description', UPLOADS_URL . "/{$job['Job']
['job_description_doc']}", array('style'=>'color: #000; text-
decoration: none')); ?><br />
        <?php echo $html->image('pdf-icon.gif', array('alt'=>'',
'style'=>'vertical-align: bottom; margin-right: 5px')) ?><?php echo
$html->link('Information', UPLOADS_URL . "/{$job['Job']
['information_doc']}", array('style'=>'color: #000; text-decoration:
none')); ?>
    </fieldset>

    <fieldset style="text-align: center">
        <legend>Online Form</legend>
        <?php $linkUrl = (trim($job['Job']['leadership_form_url']) !=
'') ? $job['Job']['leadership_form_url'] : (($job['JobType']['rtype']
== 'T') ? 'teaching' : 'nonteaching') ?>
        <?php echo $html->link('Apply Online', $linkUrl) ?>
    </fieldset>
</div>

<div class="clear"></div>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to